﻿
angular.module('zdsShop.controller', [])
.controller('loadingCtrl',['$scope','$http','$state','$timeout',function($scope,$http,$state,$timeout){
    // localStorage.setItem('openapp','1');
    $scope.is_ready = false;
    $scope.check_version = function(){
        var deviceId = api.deviceId;
        var appVersion = api.appVersion;
        var params = {};
        params.method = "article.device.guide";
        var p_params = {
            deviceId: deviceId,
            appVersion: appVersion
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                // $rootScope.enter = 1;
                if(data.status==1 && data.data==1){
                    location.replace('#/guide');
                }else{
                    location.replace('#/pinPaiQuan');
                }
            }).error(function(){
                alert('网络请求超时');
            });
    };

    apiready = function() {
        $scope.is_ready = true;
        $scope.check_version();
    }
    $scope.go = function(){
        if(!$scope.is_ready){
            location.replace('#/guide');
        }
    }
}])
.controller('guideCtrl',['$scope','$http','$state','$swipers','$timeout',function($scope,$http,$state,$swipers,$timeout){
    $swipers.swp(
        '.guide-swiper',
        false,
        0,
        1,
        1,
        '.swiper-pagination',
        null,
        null,
        0,
        false,
        function(){
            return;
        }
    );
    $scope.guide_out = function(){
        // $state.go('pinPaiQuan');
        location.replace('#/pinPaiQuan');
    };
    // (function(window, location) {
        // if(localStorage.getItem('openapp')=='1'){
        //     history.replaceState(null, document.title, location.pathname+"#!/stealingyourhistory");
        //     history.pushState(null, document.title, location.pathname);
        //     window.addEventListener("popstate", function() {
        //         console.log(location.hash);
        //         if(location.hash === "#!/stealingyourhistory") {
        //             history.replaceState(null, document.title, location.pathname+'#/loading');
        //             $timeout(function(){
        //                 location.replace("");
        //             },0);
        //         }
        //     }, false);
        // }
    // }(window, location));
}])
.controller('tuiKuanWeiDaoHuoCtrl', ['$scope', '$http', '$state',"$zhaopianSelect", function($scope, $http, $state,$zhaopianSelect) {

        $scope.order_id = angular.fromJson(localStorage.getItem('order_id')).data;
        $scope.detail_id = angular.fromJson(localStorage.getItem('detail_id')).data;
        $scope.refundType = angular.fromJson(localStorage.getItem('refundType')).data;

        $scope.liyou = "请选择";
        $scope.liyou1 = "请选择";
        var tuikuanimg = [];
        //减掉图片
        $scope.add_img_ov=true;
        $scope.jianshao=function(index){
            tuikuanimg.splice(index,1);
            $scope.imgList=tuikuanimg;
            if(tuikuanimg.length<5&&tuikuanimg.length>0){
                $scope.add_img=true;
            }else if(tuikuanimg.length==0){
                $scope.add_img=false;
                $scope.add_img_ov=true;
            }
        };
        $scope.zhaopian=function(){
          $zhaopianSelect.zpslt(1,function(ret){
              if(ret != undefined){
                $(".gwc_zzc_queren").toggleClass("disnone");
                  var img = "file://" + ret; //imgurl 就是你的图片路径
                  function getBase64Image(img) {
                      var canvas = document.createElement("canvas");
                      canvas.width = img.width;
                      canvas.height = img.height;
                      // var quality = 0.7;
                      var ctx = canvas.getContext("2d");
                      ctx.drawImage(img, 0, 0, img.width, img.height);
                      var ext = img.src.substring(img.src.lastIndexOf(".") + 1).toLowerCase();
                      var dataURL = canvas.toDataURL("image/" + ext);
                      return dataURL;
                  }
                  var image = new Image();
                  image.src = img;
                  var imgtxt = [];
                  var n = 300;
                  image.onload = function() {
                      var r = getBase64Image(image);
                      // $("#image").attr("src", r);
                      for(var i =0,l = r.length;i<l/n;i++){
                          var a = r.slice(n*i,n*(i+1));
                          imgtxt[i]=a;
                      }
                      var params = {};
                      params.method = "refund.upload.img";
                      params.id=$scope.tuikuandata.platform_record_detail_id;
                      $http({
                          method:'POST',
                          url:baison.get_url('api/', params),
                          data:{imgtxt:imgtxt}
                      }).success(function(data){
                        if(data.data == undefined){
                          $(".gwc_zzc_queren").toggleClass("disnone");
                          alert("图片过大请重新上传,图片大小不能超过2M");
                        }else{
                          if(tuikuanimg.length<5){
                            tuikuanimg.push(data.data.img);
                            $scope.imgList= tuikuanimg;
                              $scope.add_img_ov=false;
                              $scope.add_img=true;
                              if(tuikuanimg.length>=5){
                                  $scope.add_img=false;
                              }
                            // //(JSON.stringify(tuikuanimg));
                            //for(var i = 0;i<tuikuanimg.length;i++){
                            //    $scope.imgList= tuikuanimg;
                            //  $(".voucher").eq(i).attr("src",tuikuanimg[i]);
                            //  // //(tuikuanimg[i]);
                            //}
                            $(".gwc_zzc_queren").toggleClass("disnone");
                          }else{
                            alert("图片上传最多5张");
                            $(".gwc_zzc_queren").toggleClass("disnone");
                          }
                        }
                      }).error(function(data){
                          // //(data);
                      });
                  }
              }

          });
        };
        $scope.tijiaoshenqing = function() {
          if(tuikuanimg[0]!=undefined){
            voucher1 = tuikuanimg[0];
          }else{
            voucher1 = "";
          }
          if(tuikuanimg[1]!=undefined){
            voucher2 = tuikuanimg[1];
          }else{
            voucher2 = "";
          }
          if(tuikuanimg[2]!=undefined){
            voucher3 = tuikuanimg[2];
          }else{
            voucher3 = "";
          }
          if(tuikuanimg[3]!=undefined){
            voucher4 = tuikuanimg[3];
          }else{
            voucher4 = "";
          }
          if(tuikuanimg[4]!=undefined){
            voucher5 = tuikuanimg[4];
          }else{
            voucher5 = "";
          }
          var liyouxuanze,liyouxuanze1;
          if($scope.liyou == "请选择"){
            liyouxuanze = "";
          }else{
            liyouxuanze = $scope.liyou;
          }
          if($scope.liyou1 == "请选择"){
            liyouxuanze1 = "";
          }else{
            liyouxuanze1 = $scope.liyou1;
          }

          var params = {};
          params.method = "refund.apply.refund";
          var p_params = {
              id: $scope.tuikuandata.pid,
              rd_id: $scope.tuikuandata.platform_record_detail_id,
              refund_fee:$scope.tuikuan.money,
              refund_type:$scope.refundType? $scope.refundType:$scope.zhuangtainum,
              reason: liyouxuanze!='' ? liyouxuanze:liyouxuanze1,
              // reason: liyouxuanze1,
              desc:$scope.data.tuikuanshuoming,
              voucher1:voucher1,
              voucher2:voucher2,
              voucher3:voucher3,
              voucher4:voucher4,
              voucher5:voucher5
          };
          params.params = JSON.stringify(p_params);
          $http.get(baison.get_url('api/', params))
              .success(function(data) {
                if(data.status >= 0){
                  $state.go("woDeDingDan");
                }else{
                  alert(data.message);
                  return;
                }
              })
        };
        var params = {};
        params.method = "order.trade.get";
        var p_params = {
            order_id:$scope.order_id,
            detail_id:$scope.detail_id
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                if (data.code == 1) {
                    $scope.data = data.data;
                    $scope.tuikuandata = data.data.detail[0];

                    if(!$scope.refundType){
                      if ($scope.data.status_name == "处理中"||$scope.data.status_name == "已发货") {
                          $scope.zhuangtaibol = true;
                          $scope.zhuangtainum = 1;
                      } else {
                          $scope.zhuangtaibol = false;
                          $scope.zhuangtainum = 2;
                      }
                    }else{
                      if($scope.refundType==1){
                          $scope.zhuangtaibol = true;
                          $scope.zhuangtainum = 1;
                      }else if($scope.refundType==2){
                          $scope.zhuangtaibol = false;
                          $scope.zhuangtainum = 2;
                      }
                    }
                    var tuikuanprice = $scope.tuikuandata.money;
                    $scope.tuikuanmon = Number(tuikuanprice).toFixed(2);
                    $scope.tuikuan = {
                        money: $scope.tuikuanmon
                    };

                    $scope.tuihuokuanyuanyin = function() {
                        $(".thsq_zzc_container_tuihuokuan").toggleClass("disnone");
                    };
                    $scope.tuikuanyuanyin = function() {
                        $(".thsq_zzc_container_tuikuan").toggleClass("disnone");
                    };
                    $scope.closeyuanyin = function(num) {
                        if (num) {
                            $scope.liyou1 = "请选择";
                            $(".thsq_zzc_container_tuihuokuan").toggleClass("disnone");
                            $(".tuihuokuan").find("img").css("display", "none");
                        } else {
                            $scope.liyou = "请选择";
                            $(".thsq_zzc_container_tuikuan").toggleClass("disnone");
                            $(".tuikuan").find("img").css("display", "none");
                        }
                    };
                    $scope.closequeding = function(num) {
                        if (num) {
                            $(".thsq_zzc_container_tuihuokuan").toggleClass("disnone");
                        } else {
                            $(".thsq_zzc_container_tuikuan").toggleClass("disnone");
                        }
                    };
                    $('.tuikuanjine').focus(function() {
                        $(".wddd_yuanyiin").find("i").addClass("disnone");
                    });
                    $scope.tuikuanliyou = function($event) {
                        // //($($event.target).parents().hasClass("thdd_li_list"));
                        if ($($event.target).parents().hasClass("thdd_li_list")) {
                            if ($($event.target).parents("li").find("span").html() == undefined) {
                                $scope.liyou = $($event.target).find("span").html();
                                $(".tuikuan").find("img").css("display", "none");
                                $($event.target).find("img").toggle();
                            } else {
                                $scope.liyou = $($event.target).parents("li").find("span").html();
                                $(".tuikuan").find("img").css("display", "none");
                                $($event.target).parents("li").find("img").toggle();
                            }
                        }
                    };
                    $scope.tuihuokuanliyou = function($event) {
                        if ($($event.target).parents().hasClass("thdd_li_list")) {
                            if ($($event.target).parents("li").find("span").html() == undefined) {
                                $scope.liyou1 = $($event.target).find("span").html();
                                $(".tuihuokuan").find("img").css("display", "none");
                                $($event.target).find("img").toggle();
                            } else {
                                $scope.liyou1 = $($event.target).parents("li").find("span").html();
                                $(".tuihuokuan").find("img").css("display", "none");
                                $($event.target).parents("li").find("img").toggle();
                            }
                        }
                    }
                } else {}
            });
    }])
    .controller('zhuanTiChanPinCtrl', ['$scope', '$http', '$state','$stateParams','$window', function($scope, $http, $state,$stateParams,$window) {
      var actnum = $stateParams.id;
      var params = {};
      params.method = "item.goods.special.by.sn";
      var p_params = {
          article_id: actnum
      };
      params.params = JSON.stringify(p_params);
      $http.get(baison.get_url('api/', params))
          .success(function (data) {
            $scope.data=data;
            $scope.toUrl = function(aid) {
                $state.go('chanPinXiangQing', {
                    id: aid
                })
            };
            $scope.backButton = function() {
                history.back();
            };
            $(".product_main_img_container").html(data.content);
            // zhuanTiChanPin
              if (data.status == 1) {
              } else {
                //  alert(data.message);
              }
          });
        //返回顶部
        $scope.toTop = function() {
            $('html,body').animate({
                scrollTop: 0
            }, 700);
        };
        //监听滚动事件
        $window.onscroll = function() {
            if ($(document).scrollTop() > $(window).height()) {
                $('.sc_sc_xiangshang_box').show(500);
            } else if ($(document).scrollTop() < $(window).height()) {
                $('.sc_sc_xiangshang_box').hide(500);
            }
        };
    }])
    .controller('tuiKuanYiDaoHuoCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {

    }])
    .controller('shenQingTuiKuanListCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {
        $scope.order_id = angular.fromJson(localStorage.getItem('order_id')).data;
        var params = {};
        params.method = "order.trade.get";
        var p_params = {
            order_id:$scope.order_id
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                if (data.code == 1) {
                    $scope.data = data.data;
                    $scope.shenqingtuikuan = function(order_id,detail_id,type) {
                        localStorage.setItem('order_id', angular.toJson({
                            data: order_id
                        }));
                        localStorage.setItem('detail_id', angular.toJson({
                            data: detail_id
                        }));
                        localStorage.setItem('refundType', angular.toJson({
                            data: type
                        }));
                        $state.go("tuiKuanWeiDaoHuo");
                    }
                } else {
                    //  console.log(data.message);
                }
            });
    }])
    .controller('queRenDingDanCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {

    }])
    .controller('shaoMaoJieGuoErrCtrl', ['$scope', '$http', '$state','$codeScanner', function($scope, $http, $state, $codeScanner) {
        $scope.disbol = true;
        $scope.saomiao = function() {
            $codeScanner.codescan(function(retstr) {
                var arr1 = retstr.split("#");
                var str = arr1[arr1.length - 1].substr(1);
                if(str.split("/")[0] == "chanPinXiangQing"){
                  var strnum = str.split("/")[1];
                  $state.go("chanPinXiangQing",{
                      id:strnum
                  });
                }else{
                  $toast.tan("请扫描正确的商品二维码");
                }
            }, function(retstr) {
                $scope.disbol = false;
                var retstr = retstr;
                var params = {};
                params.method = "member.get.zhengshu";
                var p_params = {
                    ids: retstr
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.zsdata = data.data;
                            // var bol = JSON.stringify($scope.zsdata).substr(8,1);
                            if ($scope.zsdata == "Y") {
                                localStorage.setItem('retstr', angular.toJson({
                                    id: retstr
                                }));
                                // $state.go("shaoMaoJieGuoSuc");
                                location.replace('#/shaoMaoJieGuoSuc');
                                // $scope.disbol = true;
                            } else if ($scope.zsdata == "N") {
                                $scope.disbol = true;
                                // $state.go("shaoMaoJieGuoErr");
                            }
                        } else {
                            $scope.disbol = true;
                            //alert(data.message);
                            alert("识别失败，请检查网络或稍后重试！");
                        }
                    });
            });
        }
    }])
    .controller('shaoMaoJieGuoSucCtrl', ['$scope', '$http', '$state','$codeScanner', function($scope, $http, $state, $codeScanner) {
        $scope.retstr = angular.fromJson(localStorage.getItem('retstr')).id;
        $scope.disbol = true;
        $scope.saomiao = function() {
            $codeScanner.codescan(function(retstr) {
                var arr1 = retstr.split("#");
                var str = arr1[arr1.length - 1].substr(1);
                if(str.split("/")[0] == "chanPinXiangQing"){
                  var strnum = str.split("/")[1];
                  $state.go("chanPinXiangQing",{
                      id:strnum
                  });
                }else{
                  $toast.tan("请扫描正确的商品二维码");
                }
            }, function(retstr) {
                $scope.disbol = false;
                var retstr = retstr;
                var params = {};
                params.method = "member.get.zhengshu";
                var p_params = {
                    ids: retstr
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.zsdata = data.data;
                            // var bol = JSON.stringify($scope.zsdata).substr(8,1);
                            if ($scope.zsdata == "Y") {
                                $scope.disbol = true;
                                $scope.retstr = retstr;
                                // localStorage.setItem('retstr', angular.toJson({
                                //     id: retstr
                                // }));
                                // $state.go("shaoMaoJieGuoSuc");
                                // $scope.disbol = true;
                            } else if ($scope.zsdata == "N") {
                                // $state.go("shaoMaoJieGuoErr");
                                location.replace('#/shaoMaoJieGuoErr');
                            }
                        } else {
                            $scope.disbol = true;
                            //alert(data.message);
                            alert("识别失败，请检查网络或稍后重试！");
                        }
                    });
            });
        }
    }])
    .controller('queRenDingDan2Ctrl', ['$rootScope', '$scope', '$http', '$state', '$toast','$openapp', '$timeout', function($rootScope, $scope, $http, $state, $toast,$openapp, $timeout) {
        var actionType = angular.fromJson(localStorage.getItem('actionType'));
        /*localStorage.setItem('actionType', angular.toJson({
            action_type: ""
        }));*/
        $scope.selectct = function(index) {
            if(index==0){
                $scope.bg01="bg";
                $scope.bg02=""
            }else{
                $scope.bg01="";
                $scope.bg02="bg"
            }

            if ($('#geren').is(':checked')) {
                $('#fptt').attr("placeholder", "请输入个人姓名");
            } else if ($('#gongsi').is(':checked')) {
                $('#fptt').attr("placeholder", "请输入单位名称");
            }
        };
        //input按钮重定义
        $scope.selectct_pay=function(index){
            $scope.select_pay_num=index;
        };
        $scope.disbol = false;
        $scope.zhifu = {
            fangshi: ""
        };
        $scope.fapiao = {
            leixing: ""
        };
        $scope.xuanzezf = function() {
            if ($scope.zhifu.fangshi == "yinlian") {
                $scope.select_pay_num=1;
                $scope.ptid = 28;
            } else if ($scope.zhifu.fangshi == "alipay") {
                $scope.select_pay_num=0;
                $scope.ptid = 3;
            } else if ($scope.zhifu.fangshi == "weixin") {
                $scope.ptid = 20;
            }
        };
        $scope.allprice = 0;
        var tongji;
        var addrid;
        var atval = "";
        var button_type = '';
        if (actionType.action_type == "fast") {
            atval = "fast";
        } else {
            atval = "";
        }
        var params = {};
        params.method = "item.order.index";
        var p_params = {
            action_type: atval,
            platform_type: 6
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                if (data.status == 1) {
                    $scope.data = data.data.goods;
                    for (var i = 0; i < $scope.data.length; i++) {
                        tongji = data.data.goods[i].price * data.data.goods[i].num;
                        $scope.allprice += tongji;
                    }
                } else {
                    alert(data.message);
                    if (data.message == "请登录") {
                        $rootScope.notLoginMark();
                    //} else if (data.status = -110) {
                    } else {
                        $state.go("woDeDingDan");
                    }
                }
            });
        $scope.tiaozhuan = function(item) {
            $state.go("chanPinXiangQing", {
                id: item
            });
        };
        params.method = "member.list.address";
        p_params = {};
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                if (data.status == 1) {
                    $scope.addrdata = data.data;
                    if ($scope.addrdata == "") {
                        $scope.disbol = true;
                    } else {
                        addrid = $scope.addrdata[0].address_id;
                    }
                } else {
                    // alert(data.message);
                }
            });
        /**
         * isSubmit正在提交订单...
         */
        $scope.isSubmit = true;
        $scope.tijiao = function() {
            if ($scope.zhifu.fangshi == "") {
                $toast.tan("请选择支付方式");
            }else if(!addrid){
                $toast.tan("未完善个人信息哦");
            } else {
                $scope.isSubmit = false;
                params.method = "item.add.order";
                p_params = {
                    action_type: atval,
                    address_id: addrid,
                    invoice_type: $scope.fapiao.leixing,
                    invoice_title: $("#fptt").val(),
                    buy_remark: $(".qrdd_mjly_box_txt").val(),
                    pay_type_id: $scope.ptid,
                    platform_type: 6
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.isSubmit = true;
                            var iddata = data.data;
                            if ($scope.zhifu.fangshi == "yinlian") {
                                $openapp.openpay(iddata, function () {
                                    //回调只有Android有效 移出
                                });
                                $timeout(function() {
                                    $state.go("zhiFuZhongJianYe",{
                                        id: $scope.zhifu.fangshi,
                                        oid: iddata
                                    });
                                }, 500);
                            } else if ($scope.zhifu.fangshi == "weixin") {
                                button_type = 'weixin';
                                var params = {};
                                params.method = "order.pay";
                                params.id = iddata;
                                params.trade_type_code = "allinpay";
                                params.platform_type = 6;
                                params.submit_type = button_type;
                                $http.get(baison.get_url('api/', params))
                                    .success(function (data) {
                                        if (data.status == 1) {
                                            $scope.data2 = data;
                                            $openapp.open(button_type, data.outpay_button, function () {
                                                //回调只有Android有效 移出
                                            });
                                            localStorage.setItem('weixin_pay_url', angular.toJson({
                                                url: data.outpay_button
                                            }));
                                            $state.go("zhiFuZhongJianYe",{
                                                id: $scope.zhifu.fangshi,
                                                oid: ""
                                            });
                                        } else {
                                            // alert(data.message);
                                        }
                                    });
                            } else if ($scope.zhifu.fangshi == "alipay") {
                                button_type = 'alipay';
                                var params = {};
                                params.method = "order.pay";
                                params.id = iddata;
                                params.trade_type_code = "allinpay";
                                params.platform_type = 6;
                                params.submit_type = button_type;
                                $http.get(baison.get_url('api/', params))
                                    .success(function (data) {
                                        if (data.status == 1) {
                                            $scope.data2 = data;
                                            $openapp.open(button_type, data.outpay_button, function () {
                                                //回调只有Android有效 移出
                                            });
                                            $timeout(function() {
                                                $state.go("zhiFuZhongJianYe",{
                                                    id: $scope.zhifu.fangshi,
                                                    oid: ""
                                                });
                                            }, 500);
                                        } else {
                                            // alert(data.message);
                                        }
                                    });
                            } else {
                                $state.go("woDeDingDan");
                            }
                        } else {
                            // alert(data.message);
                        }
                    });
            }

        };
    }])
    .controller('search22Ctrl', ['$scope', '$http', '$state', function($scope, $http, $state) {

        //获取searchId
        $scope.search = function(e) {
            var keycode = window.event ? e.keyCode : e.which;
            if (keycode == 13|| typeof keycode =='undefined') {
                var sc_search = $('#sc_search_ip').val();
                if (sc_search) {
                    localStorage.setItem('searchId', angular.toJson({
                        searchId: sc_search
                    }));
                    $state.go('souSuoJieGuo');
                }
            }
        };

        //取消按钮
        $scope.cancel = function() {
            $('#sc_search_ip').val('');
        };
        //获取热门搜索ID
        $scope.getHotId = function($event) {
            var hot_id = $event.target.id;
            localStorage.setItem('hot_id', angular.toJson({
                hot_id: hot_id
            }));
            $state.go('souSuoJieGuo');
        };

        //获取历史搜索ID
        $scope.getHistorySearch = function($event) {
            var hot_id = $event.target.id;
            localStorage.setItem('searchId', angular.toJson({
                searchId: hot_id
            }));
            $state.go('souSuoJieGuo');
        };
        //调用热门搜索
        $(function() {
            var params = {};
            params.method = "item.get.hot.search";
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        // alert('登录成功');
                        $scope.data = data.data;
                        ////(data.data);
                    } else {
                        alert(data.message);
                    }
                });
        });
        //调用历史搜索记录
        $(function() {
            var params = {};
            params.method = "item.get.search";
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        // alert('调用历史搜索记录');
                        $scope.history_data = data.data;
                       /* $('#sh_span_box_bor').on('click', 'span', function($event) {
                            $('#sc_search_ip').val($(this).html());

                        });*/
                        //(data.data);
                        //删除历史搜索记录
                        $scope.delete_history_search = function() {
                            var params = {};
                            params.method = "item.del.search";
                            $http.get(baison.get_url('api/', params))
                                .success(function(data) {
                                    if (data.status == 1) {
                                        alert('删除成功');
                                        $scope.history_data = data.data;
                                        ////(data.data);
                                    } else {
                                        alert(data.message);
                                    }
                                });
                        }
                    } else {
                        alert(data.message);
                    }
                });
        });

    }])
    .controller('search23Ctrl', ['$scope', '$http', '$state', function($scope, $http, $state) {

    }])
    .controller('shangChengCtrl', ['$scope', '$swipers', '$http', '$state', '$codeScanner', '$swipers1',"$toast", function($scope, $swipers, $http, $state, $codeScanner, $swipers1,$toast) {
        //返回顶部
        $scope.toTop = function() {
            $('html,body').animate({
                scrollTop: 0
            }, 700);
        };
        //控制跳转
        $scope.toUrl = function(aid) {
            $state.go('chanPinXiangQing', {
                id: aid
            })
        };
         $scope.toNTKF = function() {
           NTKF.im_openInPageChat('kf_9048_1509589308292');
        };

        $scope.toHotRecommendUrl = function() {
            $state.go('hotRecommend');
        };
        //监听滚动事件
        window.onscroll = function() {
            if ($(document).scrollTop() > $(window).height()) {
                $('.sc_sc_xiangshang_box').show(500);
            } else if ($(document).scrollTop() < $(window).height()) {
                $('.sc_sc_xiangshang_box').hide(500);
            }
        };
        $scope.showFooterB = 'true';
        //$scope.wfswp = $wufengswipers.wufengswp();
        // $scope.$on("$destroy", function() {
        //     $scope.stopswp = $wufengswipers.stopswp();
        // });
        $scope.disbol = true;
        $scope.saomiao = function() {
            $codeScanner.codescan(function(retstr) {
                var arr1 = retstr.split("#");
                var str = arr1[arr1.length - 1].substr(1);
                if(str.split("/")[0] == "chanPinXiangQing"){
                  var strnum = str.split("/")[1];
                  $state.go("chanPinXiangQing",{
                      id:strnum
                  });
                }else{
                  $toast.tan("请扫描正确的商品二维码");
                }
            }, function(retstr) {
                $scope.disbol = false;
                var retstr = retstr;
                var params = {};
                params.method = "member.get.zhengshu";
                var p_params = {
                    ids: retstr
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.zsdata = data.data;
                            // var bol = JSON.stringify($scope.zsdata).substr(8,1);
                            if ($scope.zsdata == "Y") {
                                localStorage.setItem('retstr', angular.toJson({
                                    id: retstr
                                }));
                                $state.go("shaoMaoJieGuoSuc");
                                // $scope.disbol = true;
                            } else if ($scope.zsdata == "N") {
                                $state.go("shaoMaoJieGuoErr");
                            }
                        } else {
                            $scope.disbol = true;
                            //alert(data.message);
                            alert("识别失败，请检查网络或稍后重试！");
                        }
                    });
            });
        }

        $scope.current_nav = 0;
        var params = {};
        params.method = "item.list.category";
        var p_params = {
            platform_type: 6,
            platform_category_code:'A001'
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                if (data.status == 1) {
                    $scope.shopL = data.data.data.son;
                    $scope.nav_data = data.data.data.son[0].son;
                    $scope.shopList = function(key){
                        $scope.nav_data = data.data.data.son[key].son;
                        $scope.current_nav = key;
                    }
                } else {
                    alert(data.message);
                }
        });

        // $scope.shopL = ['全部', '黄金', '铂金', 'K金', '钻石'];
        // $scope.shopList = function($event) {
        //     var targetContent = $event.target.innerHTML;
        //     // alert(targetContent);

        //     if (targetContent == '黄金') {
        //         localStorage.setItem('getShopId', angular.toJson({
        //             id: 241
        //         }));
        //     } else if (targetContent == 'K金') {
        //         localStorage.setItem('getShopId', angular.toJson({
        //             id: 239
        //         }));
        //     } else if (targetContent == '铂金') {
        //         localStorage.setItem('getShopId', angular.toJson({
        //             id: 240
        //         }));
        //     } else if (targetContent == '钻石') {
        //         localStorage.setItem('getShopId', angular.toJson({
        //             id: 243
        //         }));
        //     } else if (targetContent == '全部') {
        //         localStorage.setItem('getShopId', angular.toJson({
        //             id: ''
        //         }));
        //     }

        // };
        //获取专区ID
        $scope.getFenLeiId = function($event) {
            localStorage.setItem('setZhuanId', angular.toJson({
                setZhuanId: $event.target.id
            }))

        };

        //调用首页轮播
        var ShopBanner = function (){
            var params = {};
            params.method = "item.get.banner";
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.shopBanner = data.data;
                        //等遍历完成再执行
                        $scope.repeatFinish = function() {
                            $scope.swipers = $swipers.swp('.shop_banner', true, 3000, 1, 1, '.shop_banner_pag', null, null, 0, false, function() {
                                return;
                            });
                        };
                    } else {
                        alert(data.message);
                    }
                });
        };

        var GoodsPop = function (){
            $scope.showSale = false;
            var date = new Date();
            var dateGetTime = date.getTime();
            var params = {};
            params.method = "item.get.goods.pop";
            var p_params = {
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.data = data.data;
                        $scope.showSale = [];
                        for (var i = 0; i < $scope.data.length; i++) {
                            $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                            $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                            $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                            $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                            $scope.data[i].sale_start_time.getTime();
                            $scope.data[i].sale_end_time.getTime();
                            $scope.showSale[i] = false;
                            if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                $scope.showSale[i] = true;
                            } else {
                                $scope.showSale[i] = false;
                            }
                        }
                        //for(var j = 0;j<$scope.data.length;j++){
                        //    $scope.data[j].sale_price =  parseInt($scope.data[j].sale_price);
                        //}
                    } else if (data.status == -1) {
                        // //('获取失败');
                    }
                });
        };
        //调用专题产品
        var SpecialProduct = function (){
            var params = {};
            params.method = "item.goods.special.list";
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    $scope.data1 = data;
                    $scope.repeatFinish = function() {
                        // //('加载完成');
                        $scope.wfswp = $swipers1.swp('.sc_banner_zt-cont');
                    };
                    $scope.goto=function(num){
                        $state.go("zhuanTiChanPin", {
                            id: num
                        });
                    };
                    if (status == 1) {
                        // $scope.banner_img = data.data.banner_img;
                        // $scope.data1 = angular.toJson($scope.data1);
                        // $scope.repeatFinish = function() {
                        //     // //('加载完成');
                        //     $scope.wfswp = $swipers1.swp('.sc_banner_zt-cont');
                        // };
                        // var data1Index = $scope.data1.indexOf('banner_img');
                        // $scope.data1 = $scope.data1.slice(0, data1Index - 2);
                        // $scope.data1 = $scope.data1.concat('}');
                        // $scope.data1 = angular.fromJson($scope.data1);
                    } else if (data.status == -1) {
                        // //('获取失败');
                    }
                });
        };
        //大专题
        var BigSpecial = function (){
            var params = {};
            params.method = "item.big.special";
            var p_params = {
                // platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    $scope.command = data;
                    $scope.tiaoto=function(num){
                        $state.go("zhuanTiChanPin", {
                            id: num
                        });
                    }
                    $scope.sptiaoto=function(num){
                        $state.go("chanPinXiangQing", {
                            id: num
                        });
                    }
                    $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
                        $scope.swipers = $swipers.swp(".sc-zt-prduct_zs", false, 0, 4, 4, null, null, null, 0, false, function() {
                            return;
                        });
                    });
                    if (data.status == 1) {
                    } else if (data.status == -1) {
                        // //('获取失败');
                    }
                });
        }
        //猜你喜欢
        var GuessLike = function (){
            $scope.showLikeSale = [];
            var date = new Date();
            var dateGetTime = date.getTime();
            var params = {};
            params.method = "member.guess.you.like";
            var p_params = {
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.like_data = data.data;
                        for (var i = 0; i < $scope.like_data.length; i++) {
                            $scope.like_data[i].sell_price = parseInt($scope.like_data[i].sell_price);
                            $scope.like_data[i].sale_price = parseInt($scope.like_data[i].sale_price);
                            $scope.like_data[i].sale_start_time = new Date($scope.like_data[i].sale_start_time);
                            $scope.like_data[i].sale_end_time = new Date($scope.like_data[i].sale_end_time);
                            var start_time = $scope.like_data[i].sale_start_time.getTime();
                            var end_time = $scope.like_data[i].sale_end_time.getTime();
                            $scope.showLikeSale[i] = false;
                            if (start_time < dateGetTime && dateGetTime < end_time && $scope.like_data[i].goods_sale_type == 3) {
                                $scope.showLikeSale[i] = true;
                                //$scope.like_data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.like_data[i].sale_end_time.getTime() &&
                                ////($scope.data[0].sale_start_time.getTime()+'促销时间');
                                ////($scope.like_data[0].goods_sale_type);
                                ////(dateGetTime+'现在时间')
                                ////($scope.data[0].sale_end_time.getTime()+'促销时间结束');
                            } else {
                                $scope.showLikeSale[i] = false;
                            }
                        }
                        //for(var j = 0;j<$scope.data.length;j++){
                        //    $scope.data[j].sale_price =  parseInt($scope.data[j].sale_price);
                        //}
                    } else if (data.status == -1) {
                        // //('获取失败');
                    }
                });
        };
        ShopBanner();
        // $(function() {
        //         var params = {};
        //         params.method = "item.get.banner";
        //         $http.get(baison.get_url('api/', params))
        //             .success(function(data) {
        //                 if (data.status == 1) {
        //                     $scope.shopBanner = data.data;
        //                     //等遍历完成再执行
        //                     $scope.repeatFinish = function() {
        //                         $scope.swipers = $swipers.swp('.shop_banner', true, 3000, 1, 1, '.shop_banner_pag', null, null, 0, false, function() {
        //                             return;
        //                         });
        //                     };
        //                     // //($scope.shopBanner);
        //                 } else {
        //                     alert(data.message);
        //                 }
        //             });
        //     })
        //调用专题产品文章
        SpecialProduct();
        // $(function() {
        //     var params = {};
        //     params.method = "item.goods.special.list";
        //     $http.get(baison.get_url('api/', params))
        //         .success(function(data) {
        //             $scope.data1 = data;
        //             // //($scope.data1);
        //             $scope.repeatFinish = function() {
        //                 // //('加载完成');
        //                 $scope.wfswp = $swipers1.swp('.sc_banner_zt-cont');
        //             };
        //             $scope.goto=function(num){
        //               $state.go("zhuanTiChanPin", {
        //                   id: num
        //               });
        //             }
        //             if (status == 1) {
        //                 // $scope.banner_img = data.data.banner_img;
        //                 // $scope.data1 = angular.toJson($scope.data1);
        //                 // $scope.repeatFinish = function() {
        //                 //     // //('加载完成');
        //                 //     $scope.wfswp = $swipers1.swp('.sc_banner_zt-cont');
        //                 // };
        //                 // var data1Index = $scope.data1.indexOf('banner_img');
        //                 // $scope.data1 = $scope.data1.slice(0, data1Index - 2);
        //                 // $scope.data1 = $scope.data1.concat('}');
        //                 // $scope.data1 = angular.fromJson($scope.data1);
        //             } else if (data.status == -1) {
        //                 // //('获取失败');
        //             }
        //         });
        // });
        //调用人气推荐接口
        GoodsPop();
        // $(function() {
        //     $scope.showSale = false;
        //     var date = new Date();
        //     var dateGetTime = date.getTime();
        //     var params = {};
        //     params.method = "item.get.goods.pop";
        //     var p_params = {
        //         platform_type: 6
        //     };
        //     params.params = JSON.stringify(p_params);
        //     $http.get(baison.get_url('api/', params))
        //         .success(function(data) {
        //             if (data.status == 1) {
        //                 $scope.data = data.data;
        //                 $scope.showSale = [];
        //                 for (var i = 0; i < $scope.data.length; i++) {
        //                     $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
        //                     $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
        //                     $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
        //                     $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
        //                     $scope.data[i].sale_start_time.getTime();
        //                     $scope.data[i].sale_end_time.getTime();
        //                     $scope.showSale[i] = false;
        //                     if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
        //                         $scope.showSale[i] = true;
        //                     } else {
        //                         $scope.showSale[i] = false;
        //                     }
        //                 }
        //                 //for(var j = 0;j<$scope.data.length;j++){
        //                 //    $scope.data[j].sale_price =  parseInt($scope.data[j].sale_price);
        //                 //}
        //             } else if (data.status == -1) {
        //                 // //('获取失败');
        //             }
        //         });
        // });
        //调用推荐产品接口
        BigSpecial();
        // $(function() {
        //     var params = {};
        //     params.method = "item.big.special";
        //     var p_params = {
        //         // platform_type: 6
        //     };
        //     params.params = JSON.stringify(p_params);
        //     $http.get(baison.get_url('api/', params))
        //         .success(function(data) {
        //             $scope.command = data;
        //             $scope.tiaoto=function(num){
        //               $state.go("zhuanTiChanPin", {
        //                 id: num
        //               });
        //             }
        //             $scope.sptiaoto=function(num){
        //               $state.go("chanPinXiangQing", {
        //                 id: num
        //               });
        //             }
        //             $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
        //               $scope.swipers = $swipers.swp(".sc-zt-prduct_zs", false, 0, 4, 4, null, null, null, 0, false, function() {
        //                 return;
        //               });
        //             });
        //             if (data.status == 1) {
        //             } else if (data.status == -1) {
        //                 // //('获取失败');
        //             }
        //         });
        // });
        //调用猜你喜欢接口

        var Reload = function () {
            ShopBanner();
            SpecialProduct();
            GoodsPop();
            BigSpecial();
            GuessLike();
        }
        //猜你喜欢
        $(function() {
            $scope.showLikeSale = [];
            var date = new Date();
            var dateGetTime = date.getTime();
            var params = {};
            params.method = "member.guess.you.like";
            var p_params = {
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.like_data = data.data;
                        for (var i = 0; i < $scope.like_data.length; i++) {
                            $scope.like_data[i].sell_price = parseInt($scope.like_data[i].sell_price);
                            $scope.like_data[i].sale_price = parseInt($scope.like_data[i].sale_price);
                            $scope.like_data[i].sale_start_time = new Date($scope.like_data[i].sale_start_time);
                            $scope.like_data[i].sale_end_time = new Date($scope.like_data[i].sale_end_time);
                            var start_time = $scope.like_data[i].sale_start_time.getTime();
                            var end_time = $scope.like_data[i].sale_end_time.getTime();
                            $scope.showLikeSale[i] = false;
                            if (start_time < dateGetTime && dateGetTime < end_time && $scope.like_data[i].goods_sale_type == 3) {
                                $scope.showLikeSale[i] = true;
                                //$scope.like_data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.like_data[i].sale_end_time.getTime() &&
                                ////($scope.data[0].sale_start_time.getTime()+'促销时间');
                                ////($scope.like_data[0].goods_sale_type);
                                ////(dateGetTime+'现在时间')
                                ////($scope.data[0].sale_end_time.getTime()+'促销时间结束');
                            } else {
                                $scope.showLikeSale[i] = false;
                            }
                        }
                        //for(var j = 0;j<$scope.data.length;j++){
                        //    $scope.data[j].sale_price =  parseInt($scope.data[j].sale_price);
                        //}
                    } else if (data.status == -1) {
                        // //('获取失败');
                    }
                    $(function(){
                        $('.dropload_content').dropload({
                            scrollArea : window,
                            domUp : {
                                domClass   : 'dropload-up',
                                domRefresh : '<div class="dropload-refresh"><img src="image/loading.gif" alt=""></div>',
                                domUpdate  : '<div class="dropload-update"><img src="image/loading.gif" alt=""></div>',
                                domLoad    : '<div class="dropload-load"><img src="image/loading.gif" alt=""></div>'
                            },
                            loadUpFn : function(me){
                                Reload();
                                setTimeout(function(){
                                    me.resetload();
                                    // 重置页数，重新获取loadDownFn的数据
                                    //  page = 0;
                                    // 解锁loadDownFn里锁定的情况
                                    me.unlock();
                                    me.noData(false);
                                },1000)

                            },
                            threshold : 50
                        });
                    });

                });
        })
    }])

.controller('souSuoJieGuoCtrl', ['$scope', '$window', '$http', '$state', '$loadMore', '$interval', '$filter','$httpRequest', function($scope, $window, $http, $state, $loadMore, $interval, $filter,$httpRequest) {

    //控制跳转
    $scope.toUrl = function(aid) {
        $state.go('chanPinXiangQing', {
            id: aid
        })
    };
    var getShopId = angular.fromJson(localStorage.getItem('getShopId'));
    var searchId = angular.fromJson(localStorage.getItem('searchId'));
    var hot_id = angular.fromJson(localStorage.getItem('hot_id'));
    var setFenLeiId = angular.fromJson(localStorage.getItem('setFenLeiId'));
    var moRen = '';
    var date = new Date();
    var dateGetTime = date.getTime();
    $scope.data = "";
    $scope.search_list = {
        kw: ''
    }; //搜索关键词
    $scope.searchShow = true; //控制搜索结果显示

    $scope.doCollect = function(code,key){

        $httpRequest.getResult("item.collect.goods",{
            'goods_code':code,
        },function(data){
            if(data.status==1){
                $scope.data[key].is_collect = $scope.data[key].is_collect==1 ? 0:1;
            }else{
                alert(data.message);
            }
        });

    };

    //调用搜索接口
    $scope.search_item = function(e) {
        var keycode = window.event ? e.keyCode : e.which;
        if (keycode == 13 || typeof keycode =='undefined') {
            moRen = localStorage.setItem('moRen', angular.toJson({
                search_kw: $scope.search_list.kw
            }));

            $scope.data = [];
            $scope.current_page = 1;
            checkMoRen({
                'page_size':6,
                'q':$scope.search_list.kw,
                'platform_type':6,
            });

        }
    };

    if (getShopId) {
        moRen = localStorage.setItem('moRen', angular.toJson({
            getShopId: getShopId.id
        }));

        $scope.data = [];
        localStorage.removeItem('getShopId');

        checkMoRen({
            'page_size':6,
            'cat_id':getShopId.id,
            'platform_type':6,
        });


    } else if (setFenLeiId) {
        moRen = localStorage.setItem('moRen', angular.toJson({
            fenLeiId: setFenLeiId.fenLeiId
        }));

        $scope.data = [];
        localStorage.removeItem('setFenLeiId');

        checkMoRen({
            'page_size':6,
            'cat_id':setFenLeiId.fenLeiId,
            'platform_type':6,
        });

    } else if (searchId) {
        moRen = localStorage.setItem('moRen', angular.toJson({
            searchId: searchId.searchId
        }));

        $scope.data = [];
        localStorage.removeItem('searchId');

        checkMoRen({
            'page_size':6,
            'q':searchId.searchId,
            'platform_type':6,
        });

    } else if (hot_id) {
        moRen = localStorage.setItem('moRen', angular.toJson({
            hot_id: hot_id.hot_id
        }));

        $scope.data = [];
        localStorage.removeItem('hot_id');

        checkMoRen({
            'page_size':6,
            'hot_id':hot_id.hot_id,
            'platform_type':6,
        });

    }
    else{
        $scope.data = [];
        checkMoRen();
    }

    //返回顶部
    $scope.toTop = function() {
        $('html,body').animate({
            scrollTop: 0
        }, 700);
        $('.sc_sc_xiangshang_box').hide(500);
    };

    $scope.loading = true;
    function checkMoRen(params) {

        if(!$scope.show_hashcode_page){
            $scope.show_hashcode_page = [];
        }

        if(!params){
            var params = getMorenParams();
            params.page_size = 6;
        }
        if(!$scope.show_hashcode){
            $scope.show_hashcode = baison.create_sign(params);
            if(!$scope.current_page){
                $scope.current_page = 1;
                $scope.dataMerage = true;
            }
        }else{
            delete params.page_no;
            if(baison.create_sign(params) != $scope.show_hashcode){
                $scope.current_page = 1;
                $scope.show_hashcode_page = [];
                $scope.show_hashcode = baison.create_sign(params);
                $scope.dataMerage = false;
            }else{
                if(!$scope.show_hashcode_page[$scope.current_page]){
                    $scope.show_hashcode_page[$scope.current_page] = true;
                }else{
                    $scope.show_hashcode_page = [];
                    $scope.show_hashcode = '';
                }
                $scope.dataMerage = true;
            }
        }

        $scope.get = function(params,page){
            if(!$scope.loading){return;}
            $scope.loading = false;
            params.page_no = page;
            // console.info(params);

            // if($scope.show_hashcode_page[page]) return;

            $scope.current_params = params;
            //$scope.show_hashcode_page[page] = false;
            $httpRequest.getResult("item.list.items",params,function(data){
                if (data.status == 1) {
                    // console.info('传入值：'+page);
                    // console.info('当前分页值:'+$scope.current_page);
                    formatDataItem(data,false);

                    $scope.show_hashcode_page[page] = true;
                    // console.info(page);
                    // console.info($scope.show_hashcode_page[page]);
                    if (Math.ceil($scope.data_count / $scope.current_params.page_size) > 0) {
                        if($scope.current_page <= Math.ceil($scope.data_count / $scope.current_params.page_size)){
                            $scope.current_page = page + 1;
                        }
                    }
                    // console.info('增加之后分页值:'+$scope.current_page);

                } else if (!$scope.current_page && data.data.goods == '') {
                    $scope.searchShow = false;
                }
                $scope.loading = true;
            });
        }

        if(!$scope.data_count){
            $httpRequest.getResult("item.list.items.count",params,function(data){
                if (data.status == 1) {
                    // console.info(data);
                    $scope.data_count = data.data.count;
                    $scope.get(params,$scope.current_page);
                }
            });
        }else{
            $scope.get(params,$scope.current_page);
        }

    }

    function getMorenParams(){
        moRen = angular.fromJson(localStorage.getItem('moRen'));
        var params = {};
        // alert(page);
        for (var i in moRen) {
            if (i === 'getShopId') {

                params.cat_id = moRen.getShopId;
                params.platform_type = 6;

            } else if (i === 'searchId') {

                params.q = moRen.searchId;
                params.platform_type = 6;


            } else if (i === 'hot_id') {

                params.hot_id = moRen.hot_id;
                params.platform_type = 6;

            } else if (i === 'fenLeiId') {

                params.cat_id = moRen.fenLeiId;
                params.platform_type = 6;

            } else if (i === 'search_kw') {

                params.q = moRen.search_kw;
                params.platform_type = 6;

            }
        }

        return params;
    }


    function formatDataItem (data,orderby){
        $scope.showSale = [];
        $scope.searchShow = true;

        if(!$scope.data || !$scope.dataMerage) $scope.data = [];

        //合并
        var index = $scope.data.length;
        for(var i = 0;i <data.data.goods.length;i++,index++){
            $scope.data[index] = data.data.goods[i];
            // console.info($scope.data);
        }

        //$scope.data = data.data.goods;

        for (var i = 0; i < $scope.data.length; i++) {
            $scope.data[i].sku_price = parseFloat($scope.data[i].sku_price);
            $scope.data[i].sale_price = parseFloat($scope.data[i].sale_price);
            $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
            $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
            $scope.data[i].sale_start_time.getTime();
            $scope.data[i].sale_end_time.getTime();
            $scope.showSale[i] = false;
            if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                $scope.showSale[i] = true;
            } else {
                $scope.showSale[i] = false;
            }
        }

        /*if(orderby){
            orderBy();
        }*/
    }


    $scope.status = {
        sell_price: false,
        goods_sales: false,
        is_hot: false,
        sell_status: false,
        sku_price:false
    };
    //排序
    $scope.orderBy = function(filed) {
        // document.body.scrollTop = 0;
        $('.sh_soushuo_main_box_2').scrollTop(0);
        $('.sc_sc_xiangshang_box').hide();
        $scope.status[filed] = !$scope.status[filed];

        var params = getMorenParams();
        params.page_size = 6;

        if(filed == 'sell_status'){
            params.orderby = $scope.status[filed] == true ? 'onsale_time DESC' : 'onsale_time ASC';
        }else if(filed == 'collect_num'){
            params.orderby = $scope.status[filed] == true ? 'collect_num DESC' : 'collect_num ASC';
        }else if(filed == 'sku_price'){
            params.orderby = $scope.status[filed] == true ? 'sku_price DESC' : 'sku_price ASC';
        }else if(filed == 'goods_sales'){
            params.orderby = $scope.status[filed] == true ? 'sell_num DESC' : 'sell_num ASC';
        }
        checkMoRen(params);

    }

    //喜欢收藏
    //function xihuan(){
    //    var params = {};
    //    params.method = "item.collect.goods";
    //    var p_params = {
    //        goods_code: $scope.good_code
    //    };
    //    params.params = JSON.stringify(p_params);
    //    $http.get(baison.get_url('api/', params))
    //        .success(function(data) {
    //            if (data.status == 1) {
    //                $scope.data = data.data;
    //                //($scope.data);
    //            }else{
    //                alert(data.message);
    //            }
    //        });
    //}

    // setTimeout(function () {
    //     $('.scroll_box')[0].addEventListener('touchend', function (e) {
    //         $scope.loading = false;
    //         var scroll = $('.sh_soushuo_main_box_2');
    //         var paddingTop = parseFloat(scroll.css('padding-top').substr(0, scroll.css('padding-top').length - 2));
    //         var paddingBottom = parseFloat(scroll.css('padding-bottom').substr(0, scroll.css('padding-bottom').length - 2));
    //         //console.log("size： " + Math.abs(scroll[0].scrollTop + scroll[0].clientHeight - paddingTop - paddingBottom - $('.scroll_box')[0].scrollHeight) < 1)
    //         // console.log("size： " + Math.abs(scroll[0].scrollTop + scroll[0].clientHeight - paddingTop - paddingBottom - $('.scroll_box')[0].scrollHeight))
    //         if (Math.abs(scroll[0].scrollTop + scroll[0].clientHeight - paddingTop - paddingBottom - $('.scroll_box')[0].scrollHeight) < 2) {
    //             //console.log(1)
    //             e.preventDefault();
    //             //console.log($scope.current_page <= Math.ceil($scope.data_count / $scope.current_params.page_size))
    //             //checkMoRen($scope.current_params);
    //             if ($scope.current_page <= Math.ceil($scope.data_count / $scope.current_params.page_size)) {
    //                 //console.info($scope.current_params);
    //                 checkMoRen($scope.current_params);
    //             }
    //         }
    //         if ($('.sh_soushuo_main_box_2').scrollTop() > $(window).height()) {
    //             $('.sc_sc_xiangshang_box').show(500);
    //         } else if ($('.sh_soushuo_main_box_2').scrollTop() < $(window).height()) {
    //             $('.sc_sc_xiangshang_box').hide(500);
    //         }
    //     });
    // }, 200)

    setTimeout(function () {
        $('.sh_soushuo_main_box_2')[0].addEventListener('touchend', function (e) {
            var is_scroll = $loadMore.getScrollHeight()- $loadMore.getScrollTop() -$loadMore.getWindowHeight();
            if (is_scroll < 10) {
                if ($scope.current_page <= Math.ceil($scope.data_count / $scope.current_params.page_size)) {
                    //console.info($scope.current_params);
                    checkMoRen($scope.current_params);
                }
            }
            if ($(document).scrollTop() > $(window).height()) {
                $('.sc_sc_xiangshang_box').show(500);
            } else if ($(document).scrollTop() < $(window).height()) {
                $('.sc_sc_xiangshang_box').hide(500);
            }
        });
    }, 200);

    $scope.change =function (e) {
        if(e){
            $('.sc_header_box,.search_product_nav_box,.sh_soushuo_main_box_2').css('position','absolute');
            $('.sh_soushuo_main_box_2').addClass('scroll_wrap');
            $('.sh_soushuo_main_box_2').on('touchstart', function() {
                $('.sc_search_ip').blur();
            });
        }else{
            $('.sc_header_box,.search_product_nav_box,.sh_soushuo_main_box_2').css('position','static !important');
            $('.sc_header_box,.search_product_nav_box').css('position','fixed');
            $('.sh_soushuo_main_box_2').removeClass('scroll_wrap');
        }
    }
}])

.controller('hotRecommendCtrl', ['$scope', '$window', '$http', '$state', '$loadMore', '$interval', '$filter', function($scope, $window, $http, $state, $loadMore, $interval, $filter) {
        //控制跳转
        $scope.toUrl = function(aid) {
            $state.go('chanPinXiangQing', {
                id: aid
            })
        };
        var getShopId = angular.fromJson(localStorage.getItem('getShopId'));
        var searchId = angular.fromJson(localStorage.getItem('searchId'));
        var hot_id = angular.fromJson(localStorage.getItem('hot_id'));
        var setFenLeiId = angular.fromJson(localStorage.getItem('setFenLeiId'));
        var moRen = '';
        var date = new Date();
        var dateGetTime = date.getTime();
        $scope.data = "";
        $scope.search_list = {
            kw: ''
        }; //搜索关键词
        $scope.searchShow = true; //控制搜索结果显示
        //调用搜索接口
        $scope.search_item = function(e) {
            var keycode = window.event?e.keyCode:e.which;
            if(keycode == 13){
                moRen = localStorage.setItem('moRen', angular.toJson({
                    search_kw: $scope.search_list.kw
                }));
                //调用商品列表接口
                var params = {};
                params.method = "item.list.hot.recommend.items";
                var p_params = {
                    page_size: 10,
                    q: $scope.search_list.kw,
                    platform_type: 6
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.showSale = [];
                            $scope.searchShow = true;
                            $scope.data = data.data.goods;
                            for (var i = 0; i < $scope.data.length; i++) {
                                $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                $scope.data[i].sale_start_time.getTime();
                                $scope.data[i].sale_end_time.getTime();
                                $scope.showSale[i] = false;
                                if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                    $scope.showSale[i] = true;
                                } else {
                                    $scope.showSale[i] = false;
                                }

                            }
                            orderBy();
                        } else if (data.status == -1) {
                            $scope.searchShow = false;
                        }
                    });
            }
        };
        if (getShopId) {
            moRen = localStorage.setItem('moRen', angular.toJson({
                getShopId: getShopId.id
            }));
            //调用商品列表接口
            var params = {};
            params.method = "item.list.hot.recommend.items";
            var p_params = {
                page_size: 10,
                cat_id: getShopId.id,
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.showSale = [];
                        $scope.searchShow = true;
                        $scope.data = data.data.goods;
                        for (var i = 0; i < $scope.data.length; i++) {
                            $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                            $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                            $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                            $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                            $scope.data[i].sale_start_time.getTime();
                            $scope.data[i].sale_end_time.getTime();
                            if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                $scope.showSale[i] = true;
                            } else {
                                $scope.showSale[i] = false;
                            }
                        }
                        orderBy();
                        localStorage.removeItem('getShopId');
                    } else {
                        $scope.searchShow = false;
                        localStorage.removeItem('getShopId');
                    }
                });
        } else if (setFenLeiId) {
            moRen = localStorage.setItem('moRen', angular.toJson({
                fenLeiId: setFenLeiId.fenLeiId
            }));
            //调用商品列表接口
            var params = {};
            params.method = "item.list.hot.recommend.items";
            var p_params = {
                page_size: 10,
                cat_id: setFenLeiId.fenLeiId,
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.showSale = [];
                        $scope.searchShow = true;
                        $scope.data = data.data.goods;
                        for (var i = 0; i < $scope.data.length; i++) {
                            $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                            $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                            $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                            $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                            $scope.data[i].sale_start_time.getTime();
                            $scope.data[i].sale_end_time.getTime();
                            if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                $scope.showSale[i] = true;
                            } else {
                                $scope.showSale[i] = false;
                            }
                        }
                        orderBy();
                        localStorage.removeItem('setFenLeiId');
                    } else {
                        $scope.searchShow = false;
                        localStorage.removeItem('setFenLeiId');
                    }
                });
        } else if (searchId) {
            moRen = localStorage.setItem('moRen', angular.toJson({
                searchId: searchId.searchId
            }));
            //调用商品列表接口
            var params = {};
            params.method = "item.list.hot.recommend.items";
            var p_params = {
                page_size: 10,
                q: searchId.searchId,
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.showSale = [];
                        $scope.searchShow = true;
                        $scope.data = data.data.goods;
                        for (var i = 0; i < $scope.data.length; i++) {
                            $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                            $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                            $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                            $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                            $scope.data[i].sale_start_time.getTime();
                            $scope.data[i].sale_end_time.getTime();
                            if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                $scope.showSale[i] = true;
                            } else {
                                $scope.showSale[i] = false;
                            }
                        }
                        orderBy();
                        localStorage.removeItem('searchId');
                    } else {
                        $scope.searchShow = false;
                        localStorage.removeItem('searchId');
                    }
                });
        } else if (hot_id) {
            moRen = localStorage.setItem('moRen', angular.toJson({
                hot_id: hot_id.hot_id
            }));
            //调用商品列表接口
            var params = {};
            params.method = "item.list.hot.recommend.items";
            var p_params = {
                page_size: 10,
                hot_id: hot_id.hot_id,
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        // alert('获取成功');
                        $scope.showSale = [];
                        $scope.searchShow = true;
                        $scope.data = data.data.goods;
                        for (var i = 0; i < $scope.data.length; i++) {
                            $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                            $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                            $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                            $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                            $scope.data[i].sale_start_time.getTime();
                            $scope.data[i].sale_end_time.getTime();
                            if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                $scope.showSale[i] = true;
                            } else {
                                $scope.showSale[i] = false;
                            }
                        }
                        //alert($scope.data[0].sell_price);
                        orderBy();
                        localStorage.removeItem('hot_id');
                    } else {
                        $scope.searchShow = false;
                        localStorage.removeItem('hot_id');
                    }
                });
        }
        var time1 = $interval(function() {
            if ($scope.data === "") {
                moRen = angular.fromJson(localStorage.getItem('moRen'));
                for (var i in moRen) {
                    if (i === 'getShopId') {
                        var params = {};
                        params.method = "item.list.hot.recommend.items";
                        var p_params = {
                            page_size: 10,
                            cat_id: moRen.getShopId,
                            platform_type: 6
                        };
                        params.params = JSON.stringify(p_params);
                        $http.get(baison.get_url('api/', params))
                            .success(function(data) {
                                if (data.status == 1) {
                                    $scope.showSale = [];
                                    $scope.searchShow = true;
                                    $scope.data = data.data.goods;
                                    for (var i = 0; i < $scope.data.length; i++) {
                                        $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                        $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                        $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                        $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                        $scope.data[i].sale_start_time.getTime();
                                        $scope.data[i].sale_end_time.getTime();
                                        if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                            $scope.showSale[i] = true;
                                        } else {
                                            $scope.showSale[i] = false;
                                        }
                                    }
                                    orderBy();
                                    $interval.cancel(time1);

                                } else {
                                    $scope.searchShow = false;
                                    $interval.cancel(time1);
                                }
                            });
                    } else if (i === 'searchId') {
                        var params = {};
                        params.method = "item.list.hot.recommend.items";
                        var p_params = {
                            page_size: 10,
                            q: moRen.searchId,
                            platform_type: 6
                        };
                        params.params = JSON.stringify(p_params);
                        $http.get(baison.get_url('api/', params))
                            .success(function(data) {
                                if (data.status == 1) {
                                    $scope.showSale = [];
                                    $scope.searchShow = true;
                                    $scope.data = data.data.goods;
                                    for (var i = 0; i < $scope.data.length; i++) {
                                        $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                        $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                        $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                        $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                        $scope.data[i].sale_start_time.getTime();
                                        $scope.data[i].sale_end_time.getTime();
                                        $scope.showSale = [];
                                        if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                            $scope.showSale[i] = true;
                                        } else {
                                            $scope.showSale[i] = false;
                                        }
                                    }
                                    orderBy();
                                    $interval.cancel(time1);
                                } else {
                                    $scope.searchShow = false;
                                    $interval.cancel(time1);
                                }
                            });
                    } else if (i === 'hot_id') {
                        var params = {};
                        params.method = "item.list.hot.recommend.items";
                        var p_params = {
                            page_size: 10,
                            hot_id: moRen.hot_id,
                            platform_type: 6
                        };
                        params.params = JSON.stringify(p_params);
                        $http.get(baison.get_url('api/', params))
                            .success(function(data) {
                                if (data.status == 1) {
                                    $scope.showSale = [];
                                    $scope.searchShow = true;
                                    $scope.data = data.data.goods;
                                    //$scope.good_code = $scope.data[0].goods_code;
                                    //$scope.xihuan = xihuan;
                                    for (var i = 0; i < $scope.data.length; i++) {
                                        $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                        $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                        $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                        $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                        $scope.data[i].sale_start_time.getTime();
                                        $scope.data[i].sale_end_time.getTime();
                                        if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                            $scope.showSale[i] = true;
                                        } else {
                                            $scope.showSale[i] = false;
                                        }
                                    }
                                    orderBy();
                                    $interval.cancel(time1);
                                } else {
                                    $scope.searchShow = false;
                                    $interval.cancel(time1);
                                }
                            });
                    } else if (i === 'fenLeiId') {
                        var params = {};
                        params.method = "item.list.hot.recommend.items";
                        var p_params = {
                            page_size: 10,
                            cat_id: moRen.fenLeiId,
                            platform_type: 6
                        };
                        params.params = JSON.stringify(p_params);
                        $http.get(baison.get_url('api/', params))
                            .success(function(data) {
                                if (data.status == 1) {
                                    $scope.showSale = [];
                                    $scope.searchShow = true;
                                    $scope.data = data.data.goods;
                                    ////调用喜欢收藏
                                    //$scope.good_code = $scope.data[0].goods_code;
                                    //$scope.xihuan = xihuan;
                                    for (var i = 0; i < $scope.data.length; i++) {
                                        $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                        $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                        $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                        $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                        $scope.data[i].sale_start_time.getTime();
                                        $scope.data[i].sale_end_time.getTime();
                                        if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                            $scope.showSale[i] = true;
                                        } else {
                                            $scope.showSale[i] = false;
                                        }
                                    }
                                    orderBy();
                                    $interval.cancel(time1);
                                } else {
                                    $scope.searchShow = false;
                                    $interval.cancel(time1);
                                }
                            });
                    } else if (i === 'search_kw') {
                        var params = {};
                        params.method = "item.list.hot.recommend.items";
                        var p_params = {
                            page_size: 10,
                            q: moRen.search_kw,
                            platform_type: 6
                        };
                        params.params = JSON.stringify(p_params);
                        $http.get(baison.get_url('api/', params))
                            .success(function(data) {
                                if (data.status == 1) {
                                    $scope.showSale = [];
                                    $scope.searchShow = true;
                                    $scope.data = data.data.goods;
                                    for (var i = 0; i < $scope.data.length; i++) {
                                        $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                        $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                        $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                        $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                        $scope.data[i].sale_start_time.getTime();
                                        $scope.data[i].sale_end_time.getTime();
                                        if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                            $scope.showSale[i] = true;
                                        } else {
                                            $scope.showSale[i]= false;
                                        }
                                    }
                                    orderBy();
                                    $interval.cancel(time1);
                                } else {
                                    $scope.searchShow = false;
                                    $interval.cancel(time1);
                                }
                            });
                    }
                }
            }
        }, 200);

        //返回顶部
        $scope.toTop = function() {
            $('html,body').animate({
                scrollTop: 0
            }, 700);
        };
        //上拉加载更多


        $window.onscroll = function() {
            if ($loadMore.getScrollTop() + $loadMore.getWindowHeight() == $loadMore.getScrollHeight()) {
                checkMoRen();
            }
            if ($(document).scrollTop() > $(window).height()) {
                $('.sc_sc_xiangshang_box').show(500);
            } else if ($(document).scrollTop() < $(window).height()) {
                $('.sc_sc_xiangshang_box').hide(500);
            }
        };

        function checkMoRen() {
            moRen = angular.fromJson(localStorage.getItem('moRen'));
            var page = 1;
            if (Math.ceil($scope.data.length / 10) > 0) {
                page = Math.ceil($scope.data.length / 10) + 1;
            }
            for (var i in moRen) {
                if (i === 'getShopId') {
                    var params = {};
                    params.method = "item.list.hot.recommend.items";
                    var p_params = {
                        page_no: page,
                        page_size: 10,
                        cat_id: moRen.getShopId,
                        platform_type: 6
                    };
                    params.params = JSON.stringify(p_params);
                    $http.get(baison.get_url('api/', params))
                        .success(function(data) {
                            if (data.status == 1) {
                                $scope.showSale = [];
                                $scope.searchShow = true;
                                $scope.data = $scope.data.concat(data.data.goods);
                                for (var i = 0; i < $scope.data.length; i++) {
                                    $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                    $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                    $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                    $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                    $scope.data[i].sale_start_time.getTime();
                                    $scope.data[i].sale_end_time.getTime();
                                    if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                        $scope.showSale[i] = true;
                                    } else {
                                        $scope.showSale[i] = false;
                                    }
                                }
                                orderBy();
                                $interval.cancel(time1);

                            } else if (!page && data.data.goods == '') {
                                $scope.searchShow = false;
                                $interval.cancel(time1);
                            }
                        });
                } else if (i === 'searchId') {
                    var params = {};
                    params.method = "item.list.hot.recommend.items";
                    var p_params = {
                        page_no: page,
                        page_size: 10,
                        q: moRen.searchId,
                        platform_type: 6
                    };
                    params.params = JSON.stringify(p_params);
                    $http.get(baison.get_url('api/', params))
                        .success(function(data) {
                            if (data.status == 1) {
                                $scope.showSale = [];
                                $scope.searchShow = true;
                                $scope.data = $scope.data.concat(data.data.goods);
                                for (var i = 0; i < $scope.data.length; i++) {
                                    $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                    $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                    $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                    $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                    $scope.data[i].sale_start_time.getTime();
                                    $scope.data[i].sale_end_time.getTime();
                                    if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                        $scope.showSale[i] = true;
                                    } else {
                                        $scope.showSale[i] = false;
                                    }
                                }
                                orderBy();
                                $interval.cancel(time1);
                            } else if (!page && data.data.goods == '') {
                                $scope.searchShow = false;
                                $interval.cancel(time1);
                            }
                        });
                } else if (i === 'hot_id') {
                    var params = {};
                    params.method = "item.list.hot.recommend.items";
                    var p_params = {
                        page_no: page,
                        page_size: 10,
                        hot_id: moRen.hot_id,
                        platform_type: 6
                    };
                    params.params = JSON.stringify(p_params);
                    $http.get(baison.get_url('api/', params))
                        .success(function(data) {
                            if (data.status == 1) {
                                $scope.showSale = [];
                                $scope.searchShow = true;
                                $scope.data = $scope.data.concat(data.data.goods);
                                ////调用喜欢收藏
                                //$scope.good_code = $scope.data[0].goods_code;
                                //$scope.xihuan = xihuan;
                                for (var i = 0; i < $scope.data.length; i++) {
                                    $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                    $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                    $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                    $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                    $scope.data[i].sale_start_time.getTime();
                                    $scope.data[i].sale_end_time.getTime();
                                    if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                        $scope.showSale[i] = true;
                                    } else {
                                        $scope.showSale[i] = false;
                                    }
                                }
                                orderBy();
                                $interval.cancel(time1);
                            } else if (!page && data.data.goods == '') {
                                $scope.searchShow = false;
                                $interval.cancel(time1);
                            }
                        });
                } else if (i === 'fenLeiId') {
                    var params = {};
                    params.method = "item.list.hot.recommend.items";
                    var p_params = {
                        page_no: page,
                        page_size: 10,
                        cat_id: moRen.fenLeiId,
                        platform_type: 6
                    };
                    params.params = JSON.stringify(p_params);
                    $http.get(baison.get_url('api/', params))
                        .success(function(data) {
                            if (data.status == 1) {
                                $scope.showSale = [];
                                $scope.searchShow = true;
                                $scope.data = $scope.data.concat(data.data.goods);
                                for (var i = 0; i < $scope.data.length; i++) {
                                    $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                    $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                    $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                    $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                    $scope.data[i].sale_start_time.getTime();
                                    $scope.data[i].sale_end_time.getTime();
                                    if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                        $scope.showSale[i] = true;
                                    } else {
                                        $scope.showSale[i] = false;
                                    }
                                }
                                orderBy();
                                $interval.cancel(time1);
                            } else if (!page && data.data.goods == '') {
                                $scope.searchShow = false;
                                $interval.cancel(time1);
                            }
                        });
                } else if (i === 'search_kw') {
                    var params = {};
                    params.method = "item.list.hot.recommend.items";
                    var p_params = {
                        page_no: page,
                        page_size: 10,
                        q: moRen.search_kw,
                        platform_type: 6
                    };
                    params.params = JSON.stringify(p_params);
                    $http.get(baison.get_url('api/', params))
                        .success(function(data) {
                            if (data.status == 1) {
                                $scope.showSale = [];
                                $scope.searchShow = true;
                                $scope.data = $scope.data.concat(data.data.goods);
                                for (var i = 0; i < $scope.data.length; i++) {
                                    $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
                                    $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
                                    $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
                                    $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
                                    $scope.data[i].sale_start_time.getTime();
                                    $scope.data[i].sale_end_time.getTime();
                                    if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
                                        $scope.showSale[i] = true;
                                    } else {
                                        $scope.showSale[i] = false;
                                    }
                                }
                                orderBy();
                                $interval.cancel(time1);
                            } else if (!page && data.data.goods == '') {
                                $scope.searchShow = false;
                                $interval.cancel(time1);
                            }
                        });
                }
            }
        }

        //排序
        function orderBy() {
            $scope.status = {
                sell_price: false,
                goods_sales: false,
                is_hot: false,
                sell_status: false
            };
            $scope.pai = function(filed) {

                $scope.status[filed] = !$scope.status[filed];
                $scope.data = $filter('orderBy')($scope.data, filed, $scope.status[filed]);
            };
        }
        //喜欢收藏
        //function xihuan(){
        //    var params = {};
        //    params.method = "item.collect.goods";
        //    var p_params = {
        //        goods_code: $scope.good_code
        //    };
        //    params.params = JSON.stringify(p_params);
        //    $http.get(baison.get_url('api/', params))
        //        .success(function(data) {
        //            if (data.status == 1) {
        //                $scope.data = data.data;
        //                //($scope.data);
        //            }else{
        //                alert(data.message);
        //            }
        //        });
        //}
    }])


.controller('tianJiaXinDiZhiCtrl', ['$scope', '$http', '$state', '$riqiSelect','$stateParams', function($scope, $http, $state, $riqiSelect,$stateParams) {

        var address_id = $stateParams.id;
        var level1;
        var level2;
        var level3;
        if(address_id==''){
            $scope.dizhi = {
                name: "",
                phone: "",
                xiangxiaddr: ""
            };
        }else{
            var params = {};
            params.method = "member.address";
            var p_params = {
                address_id: address_id
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if(data.status==1){
                        $scope.dizhi = {
                            name: data.data.name,
                            phone: data.data.mobile,
                            xiangxiaddr: data.data.address,
                        };
                        $scope.diqu = data.data.province_name + data.data.city_name + data.data.district;
                        level1 = data.data.province_name;
                        level2 = data.data.city_name;
                        level3 = data.data.district;
                    }else{
                        alert(data.message);
                    }
                });
        }

        $scope.baocun = function() {
            if (dizhibol) {
                var params = {};
                params.method = "member.add.address";
                var p_params = {
                    name: $scope.dizhi.name,
                    address: $scope.dizhi.xiangxiaddr,
                    province: level1,
                    city: level2,
                    district: level3,
                    is_default: 1,
                    mobile: $scope.dizhi.phone,
                    address_id: address_id,
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.data = data.data;
                            $state.go("queRenDingDan2");
                        } else {
                            alert(data.message);
                        }
                    });
            } else {
                var params = {};
                params.method = "member.add.address";
                var p_params = {
                    name: $scope.dizhi.name,
                    address: $scope.dizhi.xiangxiaddr,
                    province: level1,
                    city: level2,
                    district: "",
                    is_default: 1,
                    mobile: $scope.dizhi.phone,
                    address_id: address_id,
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            $scope.data = data.data;
                            history.go(-1);
                            // $state.go("queRenDingDan2");
                        } else {
                            alert(data.message);
                        }
                    });
            }

        };
        var dizhibol = false;
        $scope.huoqudiqu = function() {
            $riqiSelect.riqi(citys, function(ret, err) {
                if (ret) {
                    // $scope.diqu=ret.level1+ret.level2+ret.level3;
                    if (ret.eventType == 'ok') {
                        level1 = ret.level1;
                        level2 = ret.level2;
                        level3 = ret.level3;
                        if (level1 == "请选择" || level1 == undefined || level2 == "请选择" || level2 == undefined || level3 == "请选择") {
                            alert("请选择正确的地址");
                        } else if (level3 == undefined) {
                            $scope.data = level1 + level2;
                            $scope.diqu = level1 + level2;
                            $scope.$apply();
                            dizhibol = false;
                        } else {
                            $scope.data = level1 + level2 + level3;
                            $scope.diqu = level1 + level2 + level3;
                            $scope.$apply();
                            dizhibol = true;
                        }
                    }

                } else {
                    //alert(JSON.stringify(err));
                }
            })
        };
        // var params = {};
        // params.method = "member.get.province";
        // $http.get(baison.get_url('api/', params))
        //     .success(function (data) {
        //         if (data.status == 1) {
        //             alert('登录成功');
        //             $scope.province = data.data.province;
        //             $scope.city = data.data.city;
        //             $scope.district = data.data.district;
        //             $scope.getProvince = function($event){
        //                 var city1 = [];
        //                 //(this.p);
        //                 //$scope.city = data.data.city;
        //                 for(var i=0 ; i<$scope.city.length;i++){
        //                     if(this.p == $scope.city[i].parent_id){
        //                         city1.push($scope.city[i]);
        //                     }
        //                 }
        //                 $scope.city = city1;
        //             };
        //             $scope.getCity = function($event){
        //                 var district1 = [];
        //                 //(this);
        //                 //$scope.city = data.data.city;
        //                 for(var i=0 ; i<$scope.district.length;i++){
        //                     if(this.c == $scope.district[i].parent_id){
        //                         district1.push($scope.district[i]);
        //                     }
        //                 }
        //                 $scope.district = district1;
        //             };
        //             //(data.data);
        //             ////(data.data[0].region_id)
        //             ////(data.data[0].parent_id)
        //             ////(data.data[0].region_name)
        //             //(data.data.province);
        //             //(data.data.city);
        //             //(data.data.district);
        //         } else {
        //             alert(data.message);
        //         }
        //     });

    }])
    .controller('tianJiaXinDiZhi2Ctrl', ['$scope', '$http', '$state', function($scope, $http, $state) {
        var selectId = "";
        var params = {};
        params.method = "member.list.address";
        $http.get(baison.get_url('api/', params))
            .success(function(data) {
                if (data.status == 1) {
                    $scope.data = data.data;
                    $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
                        for (var i = 0; i < $scope.data.length; i++) {
                            if ($scope.data[i].is_default == 1) {
                                selectId = i;
                                $(".djxdz_suc_err_box").eq(i).children().attr("src", "image/suc.png");
                            } else {
                                $(".djxdz_suc_err_box").eq(i).children().attr("src", "image/suc_weixuanzhe.png");
                            }
                        }
                    });
                    $scope.xuanze = function($event) {
                        $(".djxdz_suc_err_box img").attr("src", "image/suc_weixuanzhe.png");
                        $($event.target).attr("src", "image/suc.png");
                        selectId = $($event.target).parents(".djxdz_list_container").index();
                    };
                    $scope.baocun = function() {
                        if (undefined == $scope.data[selectId].name) {
                            alert("请添加新地址后选择保存");
                            return;
                        }
                        var params = {};
                        params.method = "member.add.address";
                        var p_params = {
                            name: $scope.data[selectId].name,
                            address: $scope.data[selectId].address,
                            province: $scope.data[selectId].province_name,
                            city: $scope.data[selectId].city_name,
                            district: $scope.data[selectId].district,
                            is_default: 1,
                            mobile: $scope.data[selectId].mobile,
                            address_id: $scope.data[selectId].address_id

                        };
                        params.params = JSON.stringify(p_params);
                        $http.get(baison.get_url('api/', params))
                            .success(function(data) {
                                if (data.status == 1) {
                                    $state.go("queRenDingDan2");
                                } else {
                                    alert(data.message);
                                }
                            });
                    }
                } else {
                    alert(data.message);
                }
            });
        // var params = {};
        // params.method = "member.get.province";
        // $http.get(baison.get_url('api/', params))
        //     .success(function (data) {
        //         if (data.status == 1) {
        //             alert('登录成功');
        //             //(data.data);
        //             ////(data.data[0].region_id)
        //             ////(data.data[0].parent_id)
        //             ////(data.data[0].region_name)
        //             //(data.data.province)
        //             //(data.data.city)
        //             //(data.data.district)
        //         } else {
        //             alert(data.message);
        //         }
        //     });

        $scope.cancel = function(addrid) {
            var params = {};
            params.method = "member.delete.address";
            var p_params = {
                address_id: addrid
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $("#" + addrid).remove();
                    } else {
                        alert(data.message);
                    }
                });

        }

        $scope.edit = function(addrid){
            $state.go('tianJiaXinDiZhi',{id:addrid});
        }

    }])

.controller('xiangQingGouMaiYeCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {

    }])
    .controller('chanPinXiangQingCtrl', ['$share','$chushihua', '$scope', '$rootScope', '$http', '$state', '$swipers', '$stateParams', "$window",function($share,$chushihua, $scope, $rootScope, $http, $state, $swipers, $stateParams,$window) {
        //返回顶部
        $scope.toTop = function() {
            $('#cpxq-wrap').animate({
                scrollTop: 0
            }, 700);
        };

        //页面置顶
         $chushihua.scrollTo();

        var shopid = angular.fromJson(localStorage.getItem('shopId')).data;
        //控制跳转
        $scope.toUrl = function(aid) {
            $state.go('chanPinXiangQing', {
                id: aid
            })
        };

        $scope.toComment = function (aid) {
            $state.go('baoBeiPingLun',{
                id: aid
            })
        };
        
        //图片滚动事件
        window.onscroll = function() {
            if ($(document).scrollTop() > ($(window).height() / 3)) {
                $('#cpxq_lf_box_1').css({
                    opacity: 0
                });
                // $('#cpxq_posit_lf').css({
                //     opacity: 0
                // });
                // $('#cpxq_posit_rt').css({
                //     opacity: 0
                // });
                $('#cpxq_posit_bt').css({
                    opacity: 0
                });
            } else if ($(document).scrollTop() < $(window).height() / 3) {
                $('#cpxq_lf_box_1').css({
                    opacity: 1
                });
                $('#cpxq_posit_lf').css({
                    opacity: 1
                });
                $('#cpxq_posit_rt').css({
                    opacity: 1
                });
                $('#cpxq_posit_bt').css({
                    opacity: 1
                });
            }
        };
        //$scope.toUrl = function() {
        //    history.back();
        //};
        $scope.chanpinnum = {
            num: ""
        };
        var gid = angular.fromJson(localStorage.getItem('shangpinID'));
        var goods_id = $stateParams.id;
        var goods_code;
        $scope.imgarr = [];
        $scope.fenleiarr = [];
        var dianjiindex;
        var dianjiindex1;
        var dianjiindex2;
        var dianjiindex3;
        var grayarr = [];
        var grayarr1 = [];
        var grayarr2 = [];
        var grayarr3 = [];
        $scope.graybolarr = [];
        $scope.graybolarr1 = [];
        $scope.graybolarr2 = [];
        $scope.graybolarr3 = [];
        $scope.ljgmysbol = [];
        $scope.ljgmcmbol = [];
        $scope.jrgwcysbol = [];
        $scope.jrgwccmbol = [];
        // $scope.jrgwcsdfj = "";
        $scope.jrgwcys = "";
        // $scope.jrgwcbs = "";
        // $scope.jrgwcsjkzfw = "";
        // $scope.jrgwcjs = "";
        // $scope.jrgwcjz = "";
        // $scope.jrgwc18kysdj = "";
        // $scope.jrgwcjddj = "";
        // $scope.jrgwczzfs = "";
        // $scope.jrgwcysys = "";
        $scope.jrgwccm = "";

        // $scope.ljgmsddj = "";
        $scope.ljgmys = "";
        // $scope.ljgmcbs = "";
        // $scope.ljgmsjkzfw = "";
        // $scope.ljgmjs = "";
        // $scope.ljgmjz = "";
        // $scope.ljgm18kysdj = "";
        // $scope.ljgmjddj = "";
        // $scope.ljgmzzfs = "";
        // $scope.ljgmysys = "";
        $scope.ljgmcm = "";
        var params = {};
        var data;
        var prnum;
        var prnum1;
        $scope.hzarr = [];
        params.method = "item.get.item.by.sn";
        var p_params = {
            id: goods_id,
            platform_type: 6
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data1) {
                data = data1;
                if (data.status == 1) {
                    $scope.data1 = data.data;
                    //分享
                    var shareText = data.data.goods_name; //获取分享的标题
                    var sharePath = location.href;
                    var hrefStart = sharePath.indexOf('#');
                    hrefStart = sharePath.slice(hrefStart);
                    var sharePathLast = baison.site + 'theme/web5/' + hrefStart;
                    $scope.shareF = function() {
                        $share.share({
                            text: shareText,
                            type: 'url',
                            path: sharePathLast
                        });
                    };
                    if (data.data.is_collect == 1) {
                        $(".footer-xihuan-box img").toggleClass("disnone");
                    }
                    $scope.gpdata = data.data.goods_photo;
                    $scope.infodata = data.data.goods_info;
                    goods_code = data.data.goods_code;
                    $scope.gddata = data.data.goods_desc;
                    $(".product_main_img_container").html($scope.gddata);

                    if (data.data.goods_comment.length==0){
                        $scope.is_more=false;
                    }else{
                        $scope.is_more=true;
                    }
                    //点击更多评论 默认显示三条
                    if(data.data.goods_comment.length>=3){
                        $scope.pldata = data.data.goods_comment.slice(0,3);
                    }

                    $scope.click_num=1;
                    $scope.more_comment=function(){
                        // $scope.click_num++;
                        // $scope.pldata = data.data.goods_comment.slice(0,10*$scope.click_num);
                        // if(3*$scope.click_num>=data.data.goods_comment.length){
                        //     alert("暂无更多评论");
                        //     $scope.is_more=false;
                        // }
                        $state.go('baoBeiPingLun');

                    };


                    $scope.skusdata = data.data.skus;
                    $scope.parameterdata = data.data.parameter;
                    $scope.scdata = data.data.spceifications;
                    // $scope.scdataChroma = data.data.specifications.chroma;
                    $scope.scdataColor = data.data.spceifications.color;
                    $scope.scdataSize = data.data.spceifications.size;
                    // $scope.price = data.data.skus[0].price;
                    if (shopid != "") {
                        $scope.xianshi.jrgwc();
                        localStorage.setItem('shopId', angular.toJson({
                            data: ""
                        }));
                    }
                    if (data.data.price_type == 1) {
                        $scope.mpbol = true;
                    } else {
                        $scope.mpbol = false;
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        $scope.hzarr.push(data.data.skus[i].price);
                    }
                    $scope.hzarr.sort(function(a, b) {
                        return a - b
                    });
                    $scope.price = $scope.hzarr[0];
                    prnum = $scope.hzarr[0];
                    prnum1 = $scope.hzarr[0];


                    //调用相关产品的接口
                    $scope.tiaoZhuan = function(item) {
                        $state.go("chanPinXiangQing", {
                            id: item
                        });
                    };
                    var date = new Date();
                    var dateGetTime = date.getTime();
                    var params = {};
                    params.method = "item.list.items";
                    var p_params = {
                        page_size: 10,
                        cat_id: $scope.data1.platform_category_id,
                        platform_type: 6
                    };
                    params.params = JSON.stringify(p_params);
                    $http.get(baison.get_url('api/', params))
                        .success(function(data) {
                            if (data.status == 1) {
                                $scope.xiangGuanData = data.data.goods;
                                for (var i = 0; i < $scope.xiangGuanData.length; i++) {
                                    $scope.xiangGuanData[i].sell_price = parseInt($scope.xiangGuanData[i].sell_price);
                                    $scope.xiangGuanData[i].sell_price = parseInt($scope.xiangGuanData[i].sell_price);
                                    $scope.xiangGuanData[i].sale_price = parseInt($scope.xiangGuanData[i].sale_price);
                                    $scope.xiangGuanData[i].sale_start_time = new Date($scope.xiangGuanData[i].sale_start_time);
                                    $scope.xiangGuanData[i].sale_end_time = new Date($scope.xiangGuanData[i].sale_end_time);
                                    $scope.xiangGuanData[i].sale_start_time.getTime();
                                    $scope.xiangGuanData[i].sale_end_time.getTime();
                                    if ($scope.xiangGuanData[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.xiangGuanData[i].sale_end_time.getTime() && $scope.xiangGuanData[i].goods_sale_type == 3) {
                                        $scope.showSale = true;
                                    } else {
                                        $scope.showSale = false;
                                    }
                                }
                            } else if (data.status == -1) {}
                        });
                    $scope.jiaru = function() {
                        if ($scope.jrgwcys != "" && $scope.jrgwccm != "") {
                            for (var i = 0; i < data.data.skus.length; i++) {

                                if ($scope.jrgwcys == data.data.skus[i].color_id && $scope.jrgwccm == data.data.skus[i].size_id) {
                                    $(".waidiv").toggleClass("divhidden");
                                    var skum = data.data.skus[i].sku;
                                    var colorCode = data.data.skus[i].color_code;
                                    var sizeCode = data.data.skus[i].size_code;
                                    $scope.price = data.data.skus[i].price;
                                    prnum = data.data.skus[i].price;
                                    var params = {};
                                    params.method = "item.add.cart";
                                    var p_params = {
                                        goods_id: goods_id,
                                        type: 1,
                                        color_code: colorCode,
                                        size_code: sizeCode,
                                        sku: skum,
                                        num: $scope.num,
                                        platform_type: 6
                                    };
                                    params.params = JSON.stringify(p_params);
                                    $http.get(baison.get_url('api/', params))
                                        .success(function(data) {
                                            if (data.status == 1) {
                                                localStorage.setItem('actionType', angular.toJson({
                                                    action_type: ""
                                                }));
                                                localStorage.setItem('shangpinID', angular.toJson(goods_id));
                                                $state.go('gouWuChe');
                                                // alert(data)
                                            } else {
                                                alert(data.message);
                                            }
                                        });
                                } else {

                                }
                            }
                        } else {
                            alert("请选择完整规格");
                        }
                    };
                    $scope.goumai = function() {
                            if ($scope.ljgmys != "" && $scope.ljgmcm != "") {
                                for (var i = 0; i < data.data.skus.length; i++) {
                                    if ($scope.ljgmys == data.data.skus[i].color_id && $scope.ljgmcm == data.data.skus[i].size_id) {
                                        $(".waidiv").toggleClass("divhidden");
                                        var skum = data.data.skus[i].sku;
                                        var colorCode = data.data.skus[i].color_code;
                                        var sizeCode = data.data.skus[i].size_code;
                                        $scope.price1 = data.data.skus[i].price;
                                        prnum1 = data.data.skus[i].price;
                                        var params = {};
                                        params.method = "item.fast.cart";
                                        var p_params = {
                                            id: goods_id,
                                            action_type: "fast",
                                            color_code: colorCode,
                                            size_code: sizeCode,
                                            num: $scope.num1,
                                            platform_type: 6
                                        };
                                        params.params = JSON.stringify(p_params);
                                        $http.get(baison.get_url('api/', params))
                                            .success(function(data) {
                                                if (data.status == 1) {
                                                    localStorage.setItem('shangpinID', angular.toJson(goods_id));
                                                    localStorage.setItem('actionType', angular.toJson({
                                                        action_type: "fast"
                                                    }));
                                                    $state.go('queRenDingDan2');
                                                } else {
                                                    if(data.message=="请登录后再购买"){
                                                      alert(data.message);
                                                        $rootScope.notLoginMark();
                                                    }else{
                                                      alert(data.message);
                                                    }

                                                }
                                            });
                                    } else {}
                                }
                            } else {
                                alert("请选择完整规格");
                            }
                        };

                    //监听滚动事件
                    // $window.onscroll = function() {
                    //     if ($(document).scrollTop() > $(window).height()) {
                    //         $('.sc_sc_xiangshang_box').show(500);
                    //     } else if ($(document).scrollTop() < $(window).height()) {
                    //         $('.sc_sc_xiangshang_box').hide(500);
                    //     }
                    // };
                    $('#cpxq-wrap').scroll(function () {
                        if ($('#cpxq-wrap').scrollTop() > $(window).height()) {
                            $('.sc_sc_xiangshang_box').show(500);
                        } else if ($('#cpxq-wrap').scrollTop() < $(window).height()) {
                            $('.sc_sc_xiangshang_box').hide(500);
                        }
                    })

                } else if (data.status == -999) {
                    alert(data.message);
                }

                //header滚动显示
                $('#cpxq-wrap').scroll(function() {
                    var winPos = $('#cpxq-wrap').scrollTop() * 0.0066;
                    if (winPos < 1.5) {
                        $("#cpxq_rgba").css("background-color", "rgba" + "(" + 255 + "," + 255 + "," + 255 + "," + winPos + ")");
                        $("#cpxq_rgba span").css("color", "rgba" + "(" + 50 + "," + 50 + "," + 50 + "," + winPos + ")");
                    }
                });
            });

        var bol = 1;
        var bol1 = 1;
        var parent;
        $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
            $scope.swipers = $swipers.swp(".cpxq_lf_box_1-cont", true, 3000, 1, 1, '.swiper-pagination', null, null, 0, false, function() {
                return;
            });
        });

        // $scope.moni = [10, 60, 70, 100, 90, 20, 30, 40, 50, 80];
        $scope.xianshi = {
            jrgwc: function() {
                $(".waidiv").toggleClass("divhidden");
                $(".jrgwc").toggleClass("disnone");
                if (bol) {

                    for (var i = 0; i < $(".jrgwcys").children().length; i++) {
                        $scope.ljgmysbol[i] = false;
                        $scope.jrgwcysbol[i] = false;
                        $scope.graybolarr[$(".jrgwcys").children().eq(i).attr("id")] = false;
                        $scope.graybolarr2[$(".jrgwcys").children().eq(i).attr("id")] = false;
                    }
                    for (var j = 0; j < $(".jrgwccm").children().size(); j++) {
                        $scope.ljgmcmbol[j] = false;
                        $scope.jrgwccmbol[j] = false;
                        $scope.graybolarr1[$(".jrgwcys").children().eq(j).attr("id")] = false;
                        $scope.graybolarr3[$(".jrgwcys").children().eq(j).attr("id")] = false;
                    }
                }

            },
            ljgm: function() {
                if (bol1) {
                    $(".waidiv").toggleClass("divhidden");

                    for (var i = 0; i < $(".jrgwcys").children().length; i++) {
                        $scope.ljgmysbol[i] = false;
                        $scope.jrgwcysbol[i] = false;
                        // $scope.graybolarr[$(".jrgwcys").children().eq(i).attr("id")] = false;
                        // $scope.graybolarr2[$(".jrgwcys").children().eq(i).attr("id")] = false;
                    }
                    for (var j = 0; j < $(".jrgwccm").children().size(); j++) {
                        $scope.ljgmcmbol[j] = false;
                        $scope.jrgwccmbol[j] = false;
                        // $scope.graybolarr1[$(".jrgwccm").children().eq(j).attr("id")] = false;
                        // $scope.graybolarr3[$(".jrgwccm").children().eq(j).attr("id")] = false;
                    }
                }
                $(".ljgm").toggleClass("disnone");
            }
        };
        $scope.num = 1;
        $scope.num1 = 1;
        $scope.zengjian = {
            jia: function() {
                $scope.num++;
                // $scope.price1 = prnum1 * $scope.num;
                $scope.price1 = prnum1;
            },
            jian: function() {
                $scope.num--;
                if ($scope.num <= 1) {
                    $scope.num = 1;
                }
                // $scope.price1 = prnum1 * $scope.num;
                $scope.price1 = prnum1;

            }
        };
        $scope.zengjian1 = {
            jia: function() {
                $scope.num1++;
                // $scope.price = prnum * $scope.num1;
                $scope.price = prnum;
            },
            jian: function() {
                $scope.num1--;
                if ($scope.num1 < 1) {
                    $scope.num1 = 1;
                }
                // $scope.price = prnum * $scope.num1;
                $scope.price = prnum;
            }
        };
        $scope.xihuan = function($event) {
            // if ($event.target.localName == "img") {
            var params = {};
            params.method = "item.collect.goods";
            var p_params = {
                goods_code: goods_code
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.data = data.data;
                        $(".footer-xihuan-box img").toggleClass("disnone");
                    } else {
                        alert(data.message);
                    }
                });
            // }
        };
        //设置价格默认值
        $scope.price = $scope.hzarr[0];
        $scope.canshuslt = function($event) {
            if ($event.target.localName == "span" && !$($event.target).hasClass("gray")) {
                parent = $($event.target).parent();

                if (parent.hasClass("jrgwcys")) {
                    $scope.jrgwcys = $($event.target).attr("id");
                    var indx = $($event.target).attr("id");
                    if (indx == dianjiindex) {
                        $scope.jrgwcysbol[indx] = !$scope.jrgwcysbol[indx];
                        if ($scope.jrgwcysbol[indx] == false) {
                            $scope.jrgwcys = "";
                            grayarr1 = [];
                            $scope.price = $scope.hzarr[0];
                            for (var j = 0; j < $(".jrgwccm").children().size(); j++) {
                                $scope.graybolarr1[$(".jrgwccm").children().eq(j).attr("id")] = false;
                            }
                        } else {
                            for (var j = 0; j < $(".jrgwccm").children().size(); j++) {
                                $scope.graybolarr1[$(".jrgwccm").children().eq(j).attr("id")] = true;
                            }
                        }
                    } else {
                        $scope.jrgwcysbol[indx] = !$scope.jrgwcysbol[indx];
                        if (dianjiindex != undefined && $scope.jrgwcysbol[dianjiindex] != false) {
                            $scope.jrgwcysbol[dianjiindex] = !$scope.jrgwcysbol[dianjiindex];
                        }
                        dianjiindex = indx;
                        for (var j = 0; j < $(".jrgwccm").children().size(); j++) {
                            $scope.graybolarr1[$(".jrgwccm").children().eq(j).attr("id")] = true;
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.jrgwcys == data.data.skus[i].color_id) {
                            grayarr1[i] = data.data.skus[i].size_id;
                        } else {
                            grayarr1[i] = "";
                        }
                    }

                    for (var j = 0; j < $(".jrgwccm").children().size(); j++) {
                        for (var z = 0; z < grayarr1.length; z++) {
                            if ($(".jrgwccm").children().eq(j).attr("id") == grayarr1[z] && data.data.skus[z].sku_status == 1) {
                                $scope.graybolarr1[$(".jrgwccm").children().eq(j).attr("id")] = false;
                            }
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.jrgwcys == data.data.skus[i].color_id && $scope.jrgwccm == data.data.skus[i].size_id) {
                            // $scope.price = data.data.skus[i].price * $scope.num1;
                            $scope.price = data.data.skus[i].price;
                            prnum = data.data.skus[i].price;
                        }
                    }
                    bol = 0;
                } else if (parent.hasClass("jrgwccm")) {
                    $scope.jrgwccm = $($event.target).attr("id");
                    var indx1 = $($event.target).attr("id");
                    if (indx1 == dianjiindex1) {
                        $scope.jrgwccmbol[indx1] = !$scope.jrgwccmbol[indx1];
                        if ($scope.jrgwccmbol[indx1] == false) {
                            $scope.jrgwccm = "";
                            grayarr = [];
                            $scope.price = $scope.hzarr[0];
                            for (var j = 0; j < $(".jrgwcys").children().size(); j++) {
                                $scope.graybolarr[$(".jrgwcys").children().eq(j).attr("id")] = false;
                            }
                        } else {
                            for (var j = 0; j < $(".jrgwcys").children().size(); j++) {
                                $scope.graybolarr[$(".jrgwcys").children().eq(j).attr("id")] = true;
                            }
                        }
                    } else {
                        $scope.jrgwccmbol[indx1] = !$scope.jrgwccmbol[indx1];
                        if (dianjiindex1 != undefined && $scope.jrgwccmbol[dianjiindex1] != false) {
                            $scope.jrgwccmbol[dianjiindex1] = !$scope.jrgwccmbol[dianjiindex1];
                        }
                        dianjiindex1 = indx1;
                        for (var j = 0; j < $(".jrgwcys").children().size(); j++) {
                            $scope.graybolarr[$(".jrgwcys").children().eq(j).attr("id")] = true;
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.jrgwccm == data.data.skus[i].size_id) {
                            grayarr[i] = data.data.skus[i].color_id;
                        } else {
                            grayarr[i] = "";
                        }
                    }

                    for (var j = 0; j < $(".jrgwcys").children().size(); j++) {
                        for (var z = 0; z < grayarr.length; z++) {
                            if ($(".jrgwcys").children().eq(j).attr("id") == grayarr[z] && data.data.skus[z].sku_status == 1) {
                                $scope.graybolarr[$(".jrgwcys").children().eq(j).attr("id")] = false;
                            }
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.jrgwcys == data.data.skus[i].color_id && $scope.jrgwccm == data.data.skus[i].size_id) {
                            $scope.price = data.data.skus[i].price;
                            prnum = data.data.skus[i].price;
                        }
                    }
                    bol = 0;
                }

                if (parent.hasClass("ljgmys")) {
                    $scope.ljgmys = $($event.target).attr("id");
                    var indx = $($event.target).attr("id");
                    if(indx == dianjiindex2){
                        $scope.ljgmysbol[indx] = !$scope.ljgmysbol[indx];
                        if($scope.ljgmysbol[indx] == false){
                            $scope.ljgmys = "";
                            grayarr1 = [];
                            $scope.price = $scope.hzarr[0];
                            for(var j = 0;j<$(".ljgmcm").children().size();j++){
                                $scope.graybolarr3[$(".ljgmcm").children().eq(j).attr("id")] = false;
                            }
                        }else{
                            for(var j = 0;j<$(".ljgmcm").children().size();j++){
                                $scope.graybolarr3[$(".ljgmcm").children().eq(j).attr("id")] = true;
                            }
                        }
                    }else{
                        $scope.ljgmysbol[indx] = !$scope.ljgmysbol[indx];
                        if(dianjiindex2 != undefined && $scope.ljgmysbol[dianjiindex2] != false){
                            $scope.ljgmysbol[dianjiindex2] = !$scope.ljgmysbol[dianjiindex2];
                        }
                        dianjiindex2 = indx;
                        for(var j = 0;j<$(".ljgmcm").children().size();j++){
                            $scope.graybolarr3[$(".ljgmcm").children().eq(j).attr("id")] = true;
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.ljgmys == data.data.skus[i].color_id) {
                            grayarr1[i]=data.data.skus[i].size_id;
                        }else{
                            grayarr1[i]="";
                        }
                    }

                    for(var j = 0;j<$(".ljgmcm").children().size();j++){
                        for(var z = 0;z<grayarr1.length;z++){
                            if ($(".ljgmcm").children().eq(j).attr("id")==grayarr1[z] && data.data.skus[z].sku_status == 1) {
                                // //($(".jrgwccm").children().eq(j).attr("id"));
                                $scope.graybolarr3[$(".ljgmcm").children().eq(j).attr("id")] = false;
                            }
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.ljgmys == data.data.skus[i].color_id && $scope.ljgmcm == data.data.skus[i].size_id) {
                            // $scope.price = data.data.skus[i].price * $scope.num1;
                            $scope.price = data.data.skus[i].price;
                            prnum = data.data.skus[i].price;
                        }
                    }
                    bol = 0;
                }

                else if (parent.hasClass("ljgmcm")) {
                    $scope.ljgmcm = $($event.target).attr("id");
                    var indx1 = $($event.target).attr("id");
                    if(indx1 == dianjiindex3){
                        $scope.ljgmcmbol[indx1] = !$scope.ljgmcmbol[indx1];
                        if($scope.ljgmcmbol[indx1] == false){
                            $scope.ljgmcm = "";
                            grayarr = [];
                            $scope.price = $scope.hzarr[0];
                            for(var j = 0;j<$(".jrgwcys").children().size();j++){
                                $scope.graybolarr2[$(".ljgmys").children().eq(j).attr("id")] = false;
                            }
                        }else{
                            for(var j = 0;j<$(".jrgwcys").children().size();j++){
                                $scope.graybolarr2[$(".ljgmys").children().eq(j).attr("id")] = true;
                            }
                        }
                    }else{
                        $scope.ljgmcmbol[indx1] = !$scope.ljgmcmbol[indx1];
                        if(dianjiindex3 != undefined && $scope.ljgmcmbol[dianjiindex3] != false){
                            $scope.ljgmcmbol[dianjiindex3] = !$scope.ljgmcmbol[dianjiindex3];
                        }
                        dianjiindex3 = indx1;
                        for(var j = 0;j<$(".ljgmys").children().size();j++){
                            $scope.graybolarr2[$(".ljgmys").children().eq(j).attr("id")] = true;
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.ljgmcm == data.data.skus[i].size_id) {
                            grayarr[i]=data.data.skus[i].color_id;
                        }else{
                            grayarr[i]="";
                        }
                    }

                    for(var j = 0;j<$(".ljgmys").children().size();j++){
                        for(var z = 0;z<grayarr.length;z++){
                            if ($(".ljgmys").children().eq(j).attr("id")==grayarr[z]&&data.data.skus[z].sku_status == 1) {
                                // //($(".jrgwcys").children().eq(j).attr("id"));
                                $scope.graybolarr2[$(".ljgmys").children().eq(j).attr("id")] = false;
                            }
                        }
                    }
                    for (var i = 0; i < data.data.skus.length; i++) {
                        if ($scope.ljgmys == data.data.skus[i].color_id && $scope.ljgmcm == data.data.skus[i].size_id) {
                            $scope.price = data.data.skus[i].price;
                            prnum = data.data.skus[i].price;
                        }
                    }
                    bol = 0;
                }
                //----------------------------------------------------------------------------//
            }
        }
    }])
    .controller('baoBeiPingLunCtrl', ['$chushihua', '$scope', '$http','$stateParams',function($chushihua, $scope, $http,$stateParams) {
        //页面置顶
        $chushihua.scrollTo();
        var goods_id = $stateParams.id;

        var params = {};
        params.method = "item.get.item.by.sn";
        var p_params = {
            id: goods_id,
            platform_type: 6
        };
        params.params = JSON.stringify(p_params);
        $http.get(baison.get_url('api/', params))
            .success(function(data1) {
                data = data1;
                if (data.status == 1) {
                    $scope.pldata = data.data.goods_comment;
                    $scope.pllength = data.data.goods_comment.length;

                } else if (data.status == -999) {
                    alert(data.message);
                }
            });

        $scope.show_fixed = false;
        $scope.controll = false;
        $scope.fixed_url = '';
        $scope.fixed_move = function(){
            $scope.controll = true;
            console.log($scope.controll);
        }
        $scope.fixed_open = function(url){
            $scope.show_fixed = true;
            $scope.fixed_url = url;
        }
        $scope.fixed_close = function(){
            if($scope.controll){
                $scope.controll = false;
                return;
            }
            $scope.show_fixed = false;
        }
    }])


    .controller('jiaRuGouWuCheCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {

    }])
    .controller('gouWuCheCtrl', ['$rootScope', '$scope', '$chushihua', '$http', '$state', '$swplist', '$toast','$httpRequest', function($rootScope, $scope, $chushihua, $http, $state, $swplist, $toast,$httpRequest) {

        $scope.showFooterD = true;
        $chushihua.scrollTo();
        $scope.bgbol = true;

        $scope.tiaozhuansc = function() {
            $state.go("shangCheng");
        };
        $scope.tiaozhuandd = function() {
            if ($scope.allprice != 0) {
                var actionType = angular.fromJson(localStorage.getItem('actionType'));
                var atval = "";
                if (actionType.action_type == "fast") {
                    atval = "fast";
                } else {
                    atval = "";
                }
                var params = {};
                params.method = "item.order.index";
                var p_params = {
                    action_type: atval,
                    platform_type: 6
                };
                params.params = JSON.stringify(p_params);
                $http.get(baison.get_url('api/', params))
                    .success(function(data) {
                        if (data.status == 1) {
                            localStorage.setItem('actionType', angular.toJson({
                                action_type: ""
                            }));
                            $state.go("queRenDingDan2");
                        } else {
                            alert(data.message);
                            if (data.message == "请登录") {
                                $rootScope.notLoginMark();
                                //} else if (data.status = -110) {
                            }
                        }
                    });
            } else {
                alert("必须选中商品才能结算");
            }
        };

        $scope.id = angular.fromJson(localStorage.getItem('shangpinID'));
        $scope.clsbol = [];

        $scope.UpdateCart = function($event, items, count) {

            var listindex = $($event.target).parents(".gwc-swp").index();
            var parnum = $('.gwc-swp').eq(listindex).find(".gwc-num").html();
            var cartID = $($event.target).attr("class");
            var cId;
            if ($($event.target).parents(".gwc-swp").find(".gwc-select").attr("selected")) {
                cId = 1;
            } else {
                cId = 0;
            }

            $httpRequest.getResult("item.update.cart", {
                    'platform_type': 6,
                    'num': Number(parnum) + count,
                    'cart_id': cartID,
                    'is_checked': cId
                }, function(data){
                    if (data.status == 1) {
                        // $scope.data = data.data;
                        $('.gwc-swp').eq(items).find(".gwc-num-input").val(Number($('.gwc-swp').eq(items).find(".gwc-num-input").val()) + count);
                        $('.gwc-swp').eq(items).find(".gwc-num").html(Number($('.gwc-swp').eq(items).find(".gwc-num").html()) + count);
                        if (Number($('.gwc-swp').eq(items).find(".gwc-num").html()) + count <= 0) {
                            $('.gwc-swp').eq(items).find(".gwc-num-input").val(1);
                            $('.gwc-swp').eq(items).find(".gwc-num").html(1);
                        }
                    } else {
                        alert(data.message);
                    }
                }
            );

            // for (var i = 0; i < $scope.dataList.length; i++) {
            //     var list = $scope.dataList[i];
            //     if (list.items == items) {
            //         list.num = parseInt(list.num) + count;
            //         if (list.num <= 0) {
            //             list.num = 1;
            //         }
            //     }
            // }
            // $scope.allPrices();
            // $scope.$apply();
        };

        $scope.tiaozhuan = function(item) {
            // console.log(item);
            $state.go("chanPinXiangQing", {
                id: item
            });
        };

        $scope.xihuan = function($event) {
            var goods_code = $scope.gwcdata[$($event.target).parents(".gwc-swp").index()].goods_code;
            $httpRequest.getResult("item.collect.goods", {
                    'goods_code': goods_code
                }, function(data){
                    if (data.status == 1) {
                        //alert(data.message);
                        $toast.tan(data.message);
                    } else {
                        //alert(data.message);
                        $toast.tan(data.message);
                    }
                }
            );

        };

        $scope.deletes = function($event, items) {
            var tfbol = "";
            var eve = $event;
            $(".gwc_zzc_queren").toggleClass("disnone");
            $scope.tfselect = function($event) {
                if ($($event.target).attr("class") == "gwc_zzc_confirm") {
                    tfbol = true;
                } else if ($($event.target).attr("class") != "gwc_zzc_confirm") {
                    tfbol = false;
                }
                $(".gwc_zzc_queren").toggleClass("disnone");
                if (tfbol) {
                    $httpRequest.getResult("item.del.cart", {
                            'cart_id': items
                        }, function(data){
                            if (data.status == 1) {
                                $scope.getCart();
                            } else {
                                alert(data.message);
                            }
                        }
                    );
                }
            };
        };

        $scope.chageBW = function() {
            $(".gwc_bj_box").toggleClass("disnone");
            $(".gwc_chenhao").toggleClass("disnone");
            $(".gwc_taotals-ctrl").toggleClass("disnone");
        };
        $scope.allsave = function($event) {
            var cId;
            if ($($event.target).attr("all_selected") == "false") {
                cId = 1;
            } else {
                cId = 0;
            }
            $httpRequest.getResult("item.update.cart.check", {
                    'platform_type': 6,
                    'is_checked': cId,
                }, function(data){
                    if (data.status == 1) {
                        $scope.getCart();
                    }else{
                        alert(data.message);
                    }}
            );
        };

        $scope.save = function($event) {
            var listindex = $($event.target).parents(".gwc-swp").index();
            var parnum = $('.gwc-swp').eq(listindex).find(".gwc-num").html();
            var cartID = $($event.target).attr("data-cls");
            var cId;
            if ($($event.target).parents(".gwc-swp").find(".gwc-select").attr("selected")) {
                //$scope.is_js=true;
                cId = 0;
            } else {
                //$scope.is_js=false;
                cId = 1;
            }

            $httpRequest.getResult("item.update.cart", {
                    'platform_type': 6,
                    'num':parnum,
                    'cart_id': cartID,
                    'is_checked': cId
                }, function(data){
                    if (data.status == 1) {
                        if(cId == 1){
                            $($event.target).parents(".gwc-swp").find(".gwc-select").attr('selected',true);
                        }else{
                            $($event.target).parents(".gwc-swp").find(".gwc-select").attr('selected',false);
                        }
                    }else{
                        alert(data.message);
                    }}
            );
        };
        $scope.allPrices = function() {
            var allprice = 0;
            $scope.allprice = 0;
            //      用angular.forEach循环dataList
            for (var i = 0; i < $(".gwc-select").size(); i++) {
                if ($('.gwc-select').eq(i).attr('selected')) {
                    allprice += Number($scope.gwcdata[i].price) * Number($('.gwc-swp').eq(i).find(".gwc-num").html());
                }
            }
            $scope.allprice = allprice.toFixed(2);
            return $scope.allprice;
        };

        $scope.$on('ngRepeatFinished', function(ngRepeatFinishedEvent) {
            var sucs = 0;
            for (var i = 0; i < $(".gwc-select").size(); i++) {
                if ($scope.gwcdata[i].is_checked == 1) {
                    $(".gwc-select").eq(i).attr("src", "image/suc.png");
                    $(".gwc-select").eq(i).attr("selected",true);
                    sucs++;
                }
            }

            if (sucs == $('.gwc-select').size()) {
                $('.all-select').attr('src', "image/suc.png");
                $('.all-select').attr('all_selected',true);
            }else{
                $('.all-select').attr('all_selected',false);
            }

            for (var i = 0; i < $scope.gwcdata.length; i++) {
                $scope.clsbol[i] = true;
                if ($scope.gwcdata[i].inv > 0) {
                    $scope.clsbol[i] = false;
                }
            }
        });

        $scope.getCart = function(){
            $httpRequest.getResult("item.cart.info", {
                    'platform_type': 6,
                }, function(data){
                    if (data.status == 1) {
                        $scope.gwcdata = data.data;
                        if ($scope.gwcdata.length == 0) {
                            $(".msg_bg").toggleClass("disnone");
                        }
                        $scope.swplist = $swplist.swplist(".gwc-swp");
                        $scope.is_js=true;
                    }else{
                        $scope.bgbol = false;
                        $(".msg_bg").toggleClass("disnone");
                    }}
            );
        };
        $scope.getCart();
    }])
    .controller('daoHanFenLeiCtrl', ['$scope', '$http', '$state', '$swplist', function($scope, $http, $state, $swplist) {
        $(function() {
            var params = {};
            params.method = "item.list.category";
            var p_params = {
                platform_type: 6
            };
            params.params = JSON.stringify(p_params);
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (data.status == 1) {
                        $scope.data = data.data.data;
                        $scope.threeFirst = $scope.data[0].son[0].son; //第三层初始化
                        $scope.oneList = [];
                        $scope.twoList = [];
                        $scope.threeList = [];
                        $scope.showEmpty = false; //显示空分类
                        $scope.showList = true; //显示二级分类
                        $scope.showThreeList = true; //显示三级分类
                        $scope.saveData = {};
                        for (var i = 0; i < $scope.data.length; i++) {
                            $scope.oneList.push($scope.data[i].son);
                            $scope.saveData[$scope.data[i].platform_category_id] = $scope.data[i].son[0].platform_category_id;
                            for (var j = 0; j < $scope.data[i].son.length; j++) {
                                $scope.twoList.push($scope.data[i].son[j]);
                                if ($scope.data[i].son[j].son) {
                                    for (var k = 0; k < $scope.data[i].son[j].son.length; k++) {
                                        $scope.threeList.push($scope.data[i].son[j].son[k])
                                    }
                                }
                            }
                        }
                        $scope.showOneList = function($event) {
                            // $('#fenLeiOne li').removeClass('dhfl_left_active');
                            $scope.selTwoId = $scope.saveData[$event.target.id];
                            $scope.showList = false;
                            $scope.twoListLast = [];
                            $scope.threeListLast = [];
                            ////($event);
                            for (var i = 0; i < $scope.twoList.length; i++) {
                                if ($event.target.id === $scope.twoList[i].pid) {
                                    $scope.twoListLast.push($scope.twoList[i]);
                                }
                            }
                            for (var h = 0; h < $scope.twoListLast.length; h++) {
                                if ($scope.twoListLast[h].son) {
                                    for (var j = 0; j < $scope.twoListLast[h].son.length; j++) {
                                        if ($scope.saveData[$event.target.id] == $scope.twoListLast[h].son[j].pid) {
                                            $scope.threeListLast.push($scope.twoListLast[h].son[j]);
                                        }
                                    }
                                }
                            }
                            if (!$scope.threeListLast[0]) {
                                $scope.showEmpty = true;
                            } else {
                                $scope.showEmpty = false;
                            }
                            if ($scope.threeListLast) {
                                $scope.showThreeList = false;
                            }
                        };
                        $scope.showTwoList = function($event) {
                            if ($scope.twoListLast) {
                                $scope.showList = false;
                                $scope.saveData[$scope.twoListLast[0].pid] = $event.target.id;
                            } else {
                                $scope.saveData[$scope.data[0].platform_category_id] = $event.target.id;
                            }
                            $scope.selTwoId = $event.target.id;

                            $scope.threeListLast = [];
                            for (var i = 0; i < $scope.threeList.length; i++) {
                                if ($event.target.id === $scope.threeList[i].pid) {
                                    $scope.threeListLast.push($scope.threeList[i]);
                                }
                            }
                            if (i == $scope.threeList.length && $scope.threeListLast) {
                                $scope.showThreeList = false;
                            }
                            if (i == $scope.threeList.length && !$scope.threeListLast[0]) {
                                $scope.showEmpty = true;
                            } else {
                                $scope.showEmpty = false;
                            }
                        };

                        //获取第三层分类ID
                        $scope.showThreeList1 = function($event) {
                            if ($event.target.nodeName == 'IMG' || $event.target.nodeName == 'P') {
                                var fenLeiId = $event.target.parentNode.id;
                                localStorage.setItem('setFenLeiId', angular.toJson({
                                    fenLeiId: fenLeiId
                                }));
                                $state.go('souSuoJieGuo');
                            } else {
                                var fenLeiId = $event.target.id;
                                localStorage.setItem('setFenLeiId', angular.toJson({
                                    fenLeiId: fenLeiId
                                }));
                                $state.go('souSuoJieGuo');
                            }
                        };

                        $('#cai_liao').on('click', 'span', function() {
                            $(this).addClass('dh_head_active').parent().siblings().children().removeClass('dh_head_active');
                        });
                        $('#fenLeiOne').on('click', 'li', function() {
                            $(this).addClass('dhfl_left_active').siblings().removeClass('dhfl_left_active');
                        });
                    } else if (data.status == -1) {
                        // //('获取失败');
                    }
                });
        });
    }])
    .controller('shangChengErJiCtrl', ['$scope', '$filter', '$http', '$state','$httpRequest', function($scope, $filter, $http, $state,$httpRequest) {
        //控制跳转
        $scope.goUrl = function(id) {
            $state.go('chanPinXiangQing', {
                id: id
            })
        };
        var getZhuanId = angular.fromJson(localStorage.getItem('setZhuanId'));
        switch (getZhuanId.setZhuanId) {
            case "p_dring":
                $scope.ejname = "对戒";
                break;
            case "pendant":
                $scope.ejname = "吊坠";
                break;
            case "earrings":
                $scope.ejname = "耳饰";
                break;
            case "ring":
                $scope.ejname = "戒指";
                break;
            case "necklace":
                $scope.ejname = "项链";
                break;
            case "bracelet":
                $scope.ejname = "手链";
                break;
        }
        $scope.lessPrice = {
            kw: ''
        };
        $scope.mostPrice = {
            kw: ''
        };
        $scope.showFenLei = false;
        $scope.showSale = [];
        var date = new Date();
        var dateGetTime = date.getTime();
        //控制模态框
        $scope.showControl = function() {
            $scope.showFenLei = !$scope.showFenLei;
        };

        $scope.collect = function(goods_code){
            $httpRequest.getResult("item.collect.goods",{
                'goods_code':goods_code,
            },function(data){
                if (data.status == 1) {
                    //$scope.data = data.data;
                    $("#"+goods_code).toggleClass("icon_active");
                } else {
                    alert(data.message);
                }
            });
        };

        $scope.itemShowmodel = function(){
            if(parseFloat($scope.lessPrice.kw) < 0 || (isNaN(parseFloat($scope.lessPrice.kw)) && $scope.lessPrice.kw != '')){
                alert('最小价格必须大于0');
                $scope.lessPrice.kw = '';
                $scope.showFenLei = !$scope.showFenLei;
                return;
            }else if(parseFloat($scope.mostPrice.kw) < 0 || (isNaN(parseFloat($scope.mostPrice.kw)) && $scope.mostPrice.kw != '')){
                alert('最大价格必须大于0');
                $scope.mostPrice.kw = '';
                $scope.showFenLei = !$scope.showFenLei;
                return;
            }else if(parseFloat($scope.lessPrice.kw) > 0 && parseFloat($scope.mostPrice.kw) > 0 && parseFloat($scope.lessPrice.kw) > parseFloat($scope.mostPrice.kw)){
                alert('最小价格应小于最大价格');
                $scope.showFenLei = !$scope.showFenLei;
                return;
            }
            $scope.dataPrice = [];
            var n = Math.ceil($scope.data.length / 3);
            for (var k = 0; k < $scope.data.length; k++) {
                $scope.data[k].sku_price = parseFloat($scope.data[k].sku_price);
                $scope.data[k].sale_price = parseFloat($scope.data[k].sale_price);
                $scope.data[k].sale_start_time = new Date($scope.data[k].sale_start_time);
                $scope.data[k].sale_end_time = new Date($scope.data[k].sale_end_time);
                $scope.data[k].sale_start_time.getTime();
                $scope.data[k].sale_end_time.getTime();
                $scope.data[k].goods_code = $scope.data[k].goods_code;
                $scope.showSale[k] = false;
                if ($scope.data[k].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[k].sale_end_time.getTime() && $scope.data[k].goods_sale_type == 3) {
                    $scope.showSale[k] = true;
                } else {
                    $scope.showSale[k] = false;
                }
                if ($scope.data[k].sku_price >= $scope.lessPrice.kw && $scope.data[k].sku_price <= $scope.mostPrice.kw) {
                    $scope.dataPrice.push($scope.data[k]);
                } else if ($scope.data[k].sku_price >= $scope.lessPrice.kw && !$scope.mostPrice.kw) {
                    $scope.dataPrice.push($scope.data[k]);
                } else if (!$scope.lessPrice.kw && $scope.data[k].sku_price <= $scope.mostPrice.kw) {
                    $scope.dataPrice.push($scope.data[k]);
                } else if (!$scope.lessPrice.kw && !$scope.mostPrice.kw) {
                    $scope.dataPrice.push($scope.data[k]);
                }
            }
            $scope.dataFirst = [];
            $scope.dataSecond = [];
            $scope.dataThird = [];
            $scope.showSaleFirst = [];
            $scope.showSaleSecond = [];
            $scope.showSaleThird = [];
            for (var i = 0; i < n; i++) {
                if ($scope.dataPrice[3 * i]) {
                    $scope.dataFirst.push($scope.dataPrice[3 * i]);
                    $scope.showSaleFirst.push($scope.showSale[3 * i]);
                }
                if ($scope.dataPrice[3 * i + 1]) {
                    $scope.dataSecond.push($scope.dataPrice[3 * i + 1]);
                    $scope.showSaleSecond.push($scope.showSale[3 * i + 1]);
                }
                if ($scope.dataPrice[3 * i + 2]) {
                    $scope.dataThird.push($scope.dataPrice[3 * i + 2]);
                    $scope.showSaleThird.push($scope.showSale[3 * i + 2]);
                }
            }
        };

        //价格区间排序
        $scope.pricePai = function(e) {
            //if($scope.lessPrice.kw && $scope.mostPrice.kw){
            e = typeof (e)!='undefined' ? e:'';
            if(e!=''){
                var keycode = window.event ? e.keyCode : e.which;
                if (keycode!=13 && typeof keycode != 'undefined') {
                    return;
                }
            }
            $scope.itemShowmodel();
            $scope.showFenLei = !$scope.showFenLei;
            $scope.lessPrice.kw = '';
            $scope.mostPrice.kw = '';
        };

        $scope.status = {
            sell_price: false,
            goods_sales: false,
            is_hot: false,
            sell_status: false,
            sku_price:false
        };
        //排序
        $scope.orderBy = function(filed) {
            document.body.scrollTop = 0;
            if(!filed){
                filed = 'sku_price';
            }
            $scope.status[filed] = !$scope.status[filed];

            var params = {};
            params.cat_code = angular.fromJson(localStorage.getItem('setZhuanId')).setZhuanId;
            params.platform_type = 6;

            if(filed == 'sell_status'){
                params.orderby = $scope.status[filed] == true ? 'onsale_time DESC' : 'onsale_time ASC';
            }else if(filed == 'collect_num'){
                params.orderby = $scope.status[filed] == true ? 'collect_num DESC' : 'collect_num ASC';
            }else if(filed == 'sku_price'){
                params.orderby = $scope.status[filed] == true ? 'sku_price DESC' : 'sku_price ASC';
            }else if(filed == 'goods_sales'){
                params.orderby = $scope.status[filed] == true ? 'sell_num DESC' : 'sell_num ASC';
            }

            $httpRequest.getResult("item.list.items", params , function (data) {
                if (data.status == 1) {
                    $scope.cat_img = data.data.cat_img;
                    $scope.data = data.data.goods;
                    $scope.data = $filter('orderBy')($scope.data, filed, $scope.status[filed]);
                    $scope.itemShowmodel();
                } else {
                    // //('获取失败');
                }
            });
        };
        $scope.orderBy();

    }])

    //支付中间页
    .controller('zhiFuZhongJianYeCtrl', ['$scope', '$state', '$stateParams', '$http', function ($scope, $state, $stateParams,$http) {
        $scope.pay_yl = false;
        $scope.pay_wx = false;
        $scope.pay_zfb = false;
        var fangshi_id = $stateParams.id;

        if (fangshi_id == 'weixin') {
            var params = {};
            params.method = "order.is.weixin";
            $http.get(baison.get_url('api/', params))
                .success(function(data) {
                    if (1 == data.status) {
                        $scope.pay_wx = true;
                        $scope.url = angular.fromJson(localStorage.getItem('weixin_pay_url')).url;
                    } else {
                        alert("请在微信环境中点击支付");
                        localStorage.setItem('order_tab', angular.toJson({data: "order_no_pay"}));
                        $state.go('woDeDingDan');
                    }
                });
        }
        if (fangshi_id == 'alipay' || fangshi_id == 'yinlian') {
            $scope.pay_zfb = true;
        }
        $scope.backNOPay = function () {
            localStorage.setItem('order_tab', angular.toJson({data: "order_no_pay"}));
            $state.go('woDeDingDan');
        };
        $scope.backNODelivery = function () {
            localStorage.setItem('order_tab', angular.toJson({data: "order_no_delivery"}));
            $state.go('woDeDingDan');
        };
    }])

    //完成支付控制器
    .controller('gouMaiWanChengCtrl', ['$scope', '$http', '$state', function($scope, $http, $state) {
        $scope.toWoDeDingDan = function() {
            $state.go('shangCheng');
        };
        $scope.toShangCheng = function() {
            $state.go('shangCheng');
        };
        //调用相关产品的接口
        $scope.tiaoZhuan = function(item) {
            $state.go("chanPinXiangQing", {
                id: item
            });
        };

           $(function() {
               $scope.showSale = false;
               var date = new Date();
               var dateGetTime = date.getTime();
               var params = {};
               params.method = "member.guess.you.like";
               var p_params = {
               	   limit:10,
                   platform_type: 6
               };
               params.params = JSON.stringify(p_params);
               $http.get(baison.get_url('api/', params))
                   .success(function(data) {
                       if (data.status == 1) {
                           $scope.data = data.data;
//                         $scope.showSale = [];
//                         for (var i = 0; i < $scope.data.length; i++) {
//                             $scope.data[i].sell_price = parseInt($scope.data[i].sell_price);
//                             $scope.data[i].sale_price = parseInt($scope.data[i].sale_price);
//                             $scope.data[i].sale_start_time = new Date($scope.data[i].sale_start_time);
//                             $scope.data[i].sale_end_time = new Date($scope.data[i].sale_end_time);
//                             $scope.data[i].sale_start_time.getTime();
//                             $scope.data[i].sale_end_time.getTime();
//                             $scope.showSale[i] = false;
//                             if ($scope.data[i].sale_start_time.getTime() < dateGetTime && dateGetTime < $scope.data[i].sale_end_time.getTime() && $scope.data[i].goods_sale_type == 3) {
//                                 $scope.showSale[i] = true;
//                             } else {
//                                 $scope.showSale[i] = false;
//                             }
//                         }
                       } else if (data.status == -1) {
                       }
                   });
           });
    }]);
